Slash Boxes
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 ]

cog (4665)

Journal of cog (4665)

Tuesday July 05, 2005
11:29 AM

A bug in perl

[ #25525 ]

perl -e '{};{}' # works
perl -e '{1}{}' # works
perl -e '{}{1}' # works
perl -e '{}{}'  # doesn't work

It should, shouldn't it? After all, it's just two empty blocks...

No, they're not.

To perl, those are two hashrefs.

In fact, to perl, there are two hashrefs in the first example and one in each of the following two.

If you don't believe me, try it yourself:

perl -MO=Terse -e '{};{}'

As for fixing that, it seems very unlikely it will ever be...

And thus ended an interesting conversation with the #p5p folks:

        <rgs> cog: does this come from generated code ?
        <cog> rgs, er... no...
        <cog> and don't you dare asking me how I came up with it
        * cog goes back to his secret experiments
        <rgs> damn.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • If I remember correctly Perl uses fuzzy logic to guess whether you meant a {} to be a block or a hash-ref. It assigns points based on the surrounding code and the stuff inside the {} and then picks based on the resulting score.


    • Good point -- I think you're supposed to put a plus-sign (unary operator) in front of the first brace if you want to be sure the compiler sees it as an anonymous hash: +{ ...}, or put a semi-colon (representing an empty statement) at the beginning of the block if you want to be sure the compiler sees it as a block: {; ...}. (Source: merlyn's Learning Perl Objects, References & Modules book, p. 40.)