in reply to strange map behavior

Why are you trying to confuse Perl by adding useless double quotes? If you drop these double quotes, it works as expected: my %h = map { $_ => $_ } @arr ;

I have noticed recently that more monks have shown this tendency to add (double) quotes where it is not necessary and I wonder where they may have picked-up such a strange idea? Is there a new "Perl for Beginners Tutorial" running loose somewhere? If so, we need to catch it and have it shot.

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

Replies are listed 'Best First'.
Re^2: strange map behavior
by revdiablo (Prior) on Feb 26, 2008 at 04:24 UTC
    I wonder where they may have picked-up such a strange idea?

    In this case, the quotes are a remnant of his fuller code (it's almost a case of "show us the real code, not an unrepresentative sample"), see Re^2: strange map behavior. But in many cases, the tendency to over-quote can be attributed to converted shell scripters. In Bourne shells (and probably many others), you need to quote your variables to have them remain discrete values -- otherwise spaces and other whitespace can break them up into multiple tokens.