Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Monday March 08, 2004
05:16 PM

qq{Bad Quotes}

[ #17818 ]

This compiles:

sub Foo::show { print 'Foo::show' };
my %class = ( name => 'Foo' );
print qq{ $class{name}->show; #};

This does not:

sub Foo::show { print 'Foo::show' };
my %class = ( 'name}' => 'Foo' );
print qq{ $class{'name}'}->show; #};

I discovered this little curiosity because some programmer is using curly braces with qq// in our code:

return qq{<span $options{attrs}>$options{title}</span>};

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • See perlop, "Gory details of parsing quoted constructs".
  • Simply adding a backslash in front of the embedded "}" character makes it work:
    sub Foo::show { print 'Foo::show' };
    my %class = ( 'name}' => 'Foo' );
    print qq{ $class{'name\}'}->show; #};
    Result:
    Foo->show; #
    • I forgot to add: escaping works for the single quoting q{} too.
      print q{ $class{'name\}'}->show; #};
      result:
      $class{'name}'}->show; #
      In this case, backslashes work as an escape character only for the closing delimiter, its pairing delimiter, and other backslashes.
      print q{\'\$\@\{\}\[\]\(\)\"\\};
      result:
      \'\$\@{}\[\]\(\)\"\