develooper Front page | perl.perl5.porters | Postings from November 2003

[perl #24455] fat comma behavior

Thread Next
November 10, 2003 15:54
[perl #24455] fat comma behavior
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #24455]
# in the subject line of all future correspondence about this issue. 
# <URL: >

[Sorry this isn't from `perlbug`, but it just seems to hang for me,
maybe due to firewall? Anyway, it doesn't require information about
my system (unless we debug the perlbug problem).]

I think the fat-comma '=>' operator behaves differently than the
documentation explains, and it is also not very DWIMey. I discussed
it a couple weeks ago on the #perl IRC channel and on a mailing list,
and got mixed reactions as to whether it's actually a bug. From
`perldoc perldata`:

    The "=>" operator is mostly just a more visually distinctive
    synonym for a comma, but it also arranges for its left-hand
    operand to be interpreted as a string--if it's a bareword
    that would be a legal identifier.

But, we have an exception, known well to programmers:

    $ perl -le'%h=(-values=>"01",-each=>"02"); print join(",",keys(%h))'

'-values' isn't an identifier, but gets quoted anyway.
However, compare to this:

    $ perl -le'%h=(-01=>"01", -02=>"02"); print join(",", keys(%h))'

The '0' goes away because '-01' gets first interpreted as an
integer, then gets quoted. And similarly:

    $ perl -le'%h=(07=>"07", 08=>"08"); print join(",", keys(%h))'
    Illegal octal digit '8' at -e line 1, at end of line
    Execution of -e aborted due to compilation errors.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About