On Jun 22, 12:49 pm, [email protected] (Rob Coops) wrote:
> On Wed, Jun 22, 2011 at 6:44 PM, josanabr <[email protected]> wrote:
> ...
> Lets dissect this a little:
>
> Lets take the inner most thing ($var2) this is obviously a scalar (or a
> reference to another variable (I'll explain why I am betting it is a scalar
> in a bit))
> Then we see the following: $var1{...} this is the way one accesses a
> variable in a hash based on the key (the thing that goes between those
> brackets). Usually the keys used in a has are scalars of course there is
> nothing stopping anyone from using complex data structures as a key but it
> is performance wise not the smartest thing to do.
> The last bit then @{...} basically says treat what is in side the brackets
> as an array (which is what one would do if one is expecting an array
> reference to be returned from $var1's value associated with key $var2.
>
> So what would the data structure look like?
> {
> "Hash key 1" => \[
> 'Array value 1',
> 'Array value 2',
> ...
> ],
> "Hash key 2" => \[
> 'Array value 1',
> 'Array value 2',
> ...
> ],
> ...
>
> }
Hm, I think it's worth noting though if you really want to
"treat what is in side the brackets as an array", you'd
likely be using a simpler data structure such as:
"Hash key 2" = [ "Array value 1", "Array value 2", ... ]
rather than:
"Hash key 2" = \[ "Array value 1", "Array value 2", ... ]
since the latter actually creates a ref to an anonymous
array. And, if it is a "ref to a ref", you'd need to deref
the original like this:
@{ ${$var1{$var2}} }
rather than just: @{ $var1{$var2} }
See: perldoc perlref
>
> Or in text form: $var1 is an hash containing keys associated with values
> which are references to arrays.
>
--
Charles DeRykus
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/