Skip to content

Bug in constant overloading? #2344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
p5pRT opened this issue Aug 9, 2000 · 4 comments
Closed

Bug in constant overloading? #2344

p5pRT opened this issue Aug 9, 2000 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 9, 2000

Migrated from rt.perl.org#3668 (status was 'resolved')

Searchable as RT3668$

@p5pRT
Copy link
Author

p5pRT commented Aug 9, 2000

From [email protected]

  package NoBill;
 
  use overload;
  sub import {
  overload​::constant q => \&string_handler;
  }

  sub string_handler {
  my ($original, $perl_guess, $use) = @​_;
  if ($use eq 'qq') {
  $original =~ s/Windows/Winblows/g;
  }
  return $original;
  }
  1;

When I say

  perl -MNoBill -le 'print "Windows rocks"'

it fails to change the string "Windows" to "Winblows". This is
because $use is set to 'q' not 'qq'. Apparently a double-quoted
string with no interpolation or \ characters is interpreted as q() not
qq(). If I write it as qq() rather than with real double-quotes, $use
is set to 'qq'. If I put in \n at the end of the literally
double-quoted string, $use reports 'qq'.

Is this a bug in Perl, a bug in the documentation, or a bug in my
brain?

(tested with perl-5.6.0)

Nat
(observing the edict​: Post No Bills :-)

@p5pRT
Copy link
Author

p5pRT commented Aug 9, 2000

From [Unknown Contact. See original ticket]

On Aug 9, Nathan Torkington said​:

When I say

perl -MNoBill -le 'print "Windows rocks"'

it fails to change the string "Windows" to "Winblows". This is
because $use is set to 'q' not 'qq'. Apparently a double-quoted
string with no interpolation or \ characters is interpreted as q() not
qq(). If I write it as qq() rather than with real double-quotes, $use
is set to 'qq'. If I put in \n at the end of the literally
double-quoted string, $use reports 'qq'.

It's Perl compile-time optimization​:

  jeffp@​hut [12​:29am] ~ #102> perl -MO=Deparse
  @​array = ("hello", 'world', qq<what's>, q!up?!, "foo!\n");
  __END__
  @​array = ('hello', 'world', q[what's], 'up?', "foo!\n");
  - syntax OK

As Larry Rosler might say, why get Perl all primed for double-quotish
interpolation when it's not going to happen?

@p5pRT
Copy link
Author

p5pRT commented Aug 9, 2000

From [Unknown Contact. See original ticket]

Jeff Pinyan writes​:

It's Perl compile-time optimization​:

Yeah, but you didn't answer my question. When I'm overloading
strings, should it report the original type of string, should the
documentation say what's going to happen, or should I give up and go
warm the crack pipe?

Nat

@p5pRT
Copy link
Author

p5pRT commented Aug 9, 2000

From [Unknown Contact. See original ticket]

On Aug 9, Nathan Torkington said​:

Jeff Pinyan writes​:

It's Perl compile-time optimization​:

Yeah, but you didn't answer my question. When I'm overloading
strings, should it report the original type of string, should the
documentation say what's going to happen, or should I give up and go
warm the crack pipe?

Ah, I think the documentation should explicitly give a caveat re constant
strings without interpolation required.

That, or give a listing of local pagers. ;)

  $nat->pass($japhy,%|);

A beta patch is​:

  =item q

  to overload C<q>-quoted strings, constant pieces of C<qq>- and
  C<qx>-quoted strings and here-documents, or quoted strings requiring
  no interpolation beyond escaping C<\> and escaping the quoting
  delimiter,

If you don't like that wording, I cite the BUGS section​:

  This document is confusing. There are grammos and misleading language
  used in places. It would seem a total rewrite is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant