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

[perl #24455] fat comma behavior

Thread Next
From:
perlbug-followup
Date:
November 10, 2003 15:54
Subject:
[perl #24455] fat comma behavior
Message ID:
rt-24455-67275.0.180218438941537@rt.perl.org
# New Ticket Created by  lannings@who.int 
# Please include the string:  [perl #24455]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24455 >


[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 CGI.pm programmers:

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

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

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

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About