Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Query about barewords

by Athanasius (Archbishop)
on Sep 06, 2012 at 14:25 UTC ( [id://992101]=note: print w/replies, xml ) Need Help??


in reply to Query about barewords

From Comma Operator:

The => operator is a synonym for the comma except that it causes a word on its left to be interpreted as a string if it begins with a letter or underscore and is composed only of letters, digits and underscores.

Hope that helps,

Athanasius <°(((><contra mundum

Replies are listed 'Best First'.
Re^2: Query about barewords
by johngg (Canon) on Sep 06, 2012 at 15:23 UTC

    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

      ...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        

Re^2: Query about barewords
by runrig (Abbot) on Sep 06, 2012 at 15:57 UTC
    The "bareword" may also start with a "-".

      It seems to treat as an octal number, converts to decimal and then stringifies by the look of it.

      $ perl -Mstrict -Mwarnings -MData::Dumper -E ' > my %hash = ( > 011 => q{nine}, > 11 => q{eleven}, > _2t => q{fruity}, > ); > print Data::Dumper->Dumpxs( [ \ %hash ], [ qw{ *hash } ] );' %hash = ( '11' => 'eleven', '_2t' => 'fruity', '9' => 'nine' ); $ $ perl -Mstrict -Mwarnings -MData::Dumper -E ' > my %hash = ( > 08 => q{eight}, > 11 => q{eleven}, > _2t => q{fruity}, > ); > print Data::Dumper->Dumpxs( [ \ %hash ], [ qw{ *hash } ] );' Illegal octal digit '8' at -e line 3, at end of line Execution of -e aborted due to compilation errors. $

      A zero on its own is fine.

      Update: I'm an idiot, I meant to post as a reply to this :-(

      Cheers,

      JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://992101]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-24 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found