Oh, but something is being dereferenced. An array of hashes is actually an array of hash references, and so each element fed into your map is a scalar hash reference. You are probably confused because you can say $pages[0]{id}, which contains an implicit arrow operator (i.e. is equivalent to $pages[0]->{id}). See Using References for some details. | [reply] [d/l] [select] |
| [reply] |
You are dereferencing: You have an array of hashes (or, more correctly an array of references to hashes) in @pages, so $_ in the map is a reference to a hash.
This is partially hidden by the normal syntax, because perl is smart enough to realise when you type $pages[1]{id} you mean $pages[1]->{id}. (Because there is no other way element 1 of @pages could be a hash: Arrays can only hold scalars, and they only way to get a hash into a scalar is to use a reference.)
| [reply] [d/l] [select] |
explain what is going on with the arrow in this context, when nothing is being dereferenced
As already explained above, you are in fact dereferencing $_ which in the context of your map is a reference to a hash.
the arrow operator, which I though was just for class methods and deferencing
Here's a summary to avoid total confusion:
There are 3 cases where the array dereferences:
- $arrayref->[0];
- $hashref->{"key"};
- $coderef->("argument");
Then there are two cases for method calls:
- $object->method; # passes $object as first argument
- SomePackage->method; # passes "SomePackage" as first argument
hth
| [reply] |
There are 3 cases where the array dereferences:
Of your three examples, only the first one has anything to do with arrays.
| [reply] |
Hardly any dereference between arrow and array :-)
| [reply] |
Update: Sorry, I addressed the wrong point. I thought I read "fat arrow". But my note on not needing the quotes still holds.
The fat arrow is the same as comma. It has the side effect of letting you not quote the left side. So
'level' , '1','id' , 4
should be exactly the same as
'level' , '1','id' , 4
as the hash constructor syntax (putting stuff between braces) just wants a list with an even number of elements, taken as alternating keys and values. That's why it works for parameter lists too.
You could actually write
level => '1', id => 4
and be even less noisy.
—John | [reply] [d/l] [select] |