Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: strange map behavior

by Anonymous Monk
on Feb 25, 2008 at 19:12 UTC ( [id://670088]=note: print w/replies, xml ) Need Help??


in reply to strange map behavior

Your using a 'fat comma' (aka the "quoting comma": =>).
The argument to the left does not need to be quoted, try this...

my %h = map { $_ => "$_" } @arr ;

Replies are listed 'Best First'.
Re^2: strange map behavior
by CountZero (Bishop) on Feb 25, 2008 at 19:44 UTC
    Your using a 'fat comma' (aka the "quoting comma": =>)

    That is a very confusing statement.

    From the mouth of the Camel:

    The => operator is just a synonym for a comma, but it's more visually distinctive and also quotes any bare identifiers to the left of it.

    $_ not being a bare identifier, the 'fat comma' is just a comma here.

    Actually my %h = map { "$_" , "$_" } @arr ; gives the same syntax error as my %h = map { "$_" => "$_" } @arr ; proving that the 'fat comma' has nothing to do with the error. It are the double quotes that confuse the interpreter.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Hey, thanks. I should have checked that the ordinary ',' operator worked similarly in this situation before I posted. I stand corrected and educated.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-29 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found