http://www.perlmonks.org?node_id=992116


in reply to Re: Query about barewords
in thread Query about barewords

Empirically, the documentation seems to be a little inaccurate as the fat comma also seems to work if the word on the left starts with a number and consists only of numbers.

$ perl -Mstrict -Mwarnings -MData::Dumper -E ' > my %hash = ( > 1 => q{one}, > 11 => q{eleven} > ); > print Data::Dumper->Dumpxs( [ \ %hash ], [ qw{ *hash } ] );' %hash = ( '11' => 'eleven', '1' => 'one' ); $ $ perl -Mstrict -Mwarnings -MData::Dumper -E ' > my %hash = ( > 1 => q{one}, > 11 => q{eleven}, > 2t => q{fruity}, > ); > print Data::Dumper->Dumpxs( [ \ %hash ], [ qw{ *hash } ] );' syntax error at -e line 5, near "2t" Execution of -e aborted due to compilation errors. $ $ perl -Mstrict -Mwarnings -MData::Dumper -E ' > my %hash = ( > 1 => q{one}, > 11 => q{eleven}, > _2t => q{fruity}, > ); > print Data::Dumper->Dumpxs( [ \ %hash ], [ qw{ *hash } ] );' %hash = ( '11' => 'eleven', '1' => 'one', '_2t' => 'fruity' ); $

I hope this is of interest.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^3: Query about barewords
by runrig (Abbot) on Sep 06, 2012 at 15:53 UTC
    ...if the word on the left starts with a number and consists only of numbers.
    As long as you don't want to keep any leading zeros.
      As long as you don't want to keep any leading zeros.

      The claim is less accurate than even that:

      % say "010 => 11" 8 11

      Also:

      % say "123456789012345678901234567890 => 30" 1.23456789012346e+029 30 % say "'123456789012345678901234567890' => 30" 123456789012345678901234567890 30

      But I've also long considered the failure of "use strict; Foo::Bar =>" to likely just be an oversight. I suspect a patch to Perl's tokenizer/parser to allow '::' in so-called barewords would not be terribly difficult and might even be accepted by p5p.

      - tye