in reply to Re^2: wantarray - surprise behaviour
in thread wantarray - surprise behaviour
Adding to what others have said, it might be easier to get your head around this concept if you think of arrays and hashes as both being fancy kinds of lists. You can assign one to the other and maintain the same information (unlike assigning a list to a scalar, which only gives you the length of the list).
@a = ( 1, 2, 3, 4 ); %h = @a; print $h{1}; # prints 2 print $h{3}; # prints 4 print $h{2}; # prints nothing (undefined hash element) @b = %h; print $b[2]; # Unknown, since the hash doesn't maintain order # Exact behavior is undefined, and often # changes between perl versions. $ref = { @a }; # $ref gets a hash ref, but the anonoymous ref # is built with an array.
"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: wantarray - surprise behaviour
by TheEnigma (Pilgrim) on Aug 31, 2004 at 20:52 UTC |