Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Difference in Hash Declaration

by anazawa (Scribe)
on May 07, 2012 at 08:13 UTC ( #969215=note: print w/replies, xml ) Need Help??

in reply to Difference in Hash Declaration

Parenthesis () creates LIST:
( 1 => 'j', 2 => 'b' )
To create a hash, we substitute the LIST for %h:
my %h = ( 1 => 'j', 2 => 'b' );
Incidentally, LIST is different from ARRAY. To create an array, we substitute LIST for @a:
my @a = ( 1 => 'j', 2 => 'b' );

Replies are listed 'Best First'.
Re^2: Difference in Hash Declaration
by jwkrahn (Monsignor) on May 07, 2012 at 11:02 UTC
    Parenthesis () creates LIST:
    print 1, 'b', 3, 'd', 5, 'f', "\n";

    I see a list there but I don't see any parentheses.

    my @stuff = map $_ + 2, 6, 7, 8, 9, 10;


    Parentheses are used for precedence.

    my %h = ( 1 => 'j', 2 => 'b' );

    There the assignment operator has higher precedence than the comma operator so the parentheses are required.

      I agree with you. Parentheses don't create LIST, are used for precedence. I'm glad you pointed out my mistake :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969215]
[ambrus]: "could evacuate to open schoolyard and then call or go back to school" => wait what? like power cycling the school building by removing all the kids and then reentering them? how would that fix the problems?

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2017-01-18 12:34 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (161 votes). Check out past polls.