--- Jeff Pinyan <[EMAIL PROTECTED]> wrote:
> On May 23, Peter Cline said:
> >Does anyone know a better way to say @{$$hash_name{arrayref}}?
>
> Doing $$foo{...} or $$foo[...] is often confusing for people to read.
> That's why the -> operator exists:
> 
>   $foo->{bar}  # is like $$foo{bar}
>   $foo->[$i]   # is like $$foo[$i]
> 
> So you could write:
> 
>   @{ $hash->{key} }
> 
> Whitespace is your friend.

This is also one of the few good uses of local(), so long as you don't
let it confuse you: you can make localised aliases to complex names.
Just make sure you understand a local() var is a GLOBAL, and use it
with proper precaution.

{ local @ary = $hash_name->{arrayref}; # @ary now the array
  print $ary[4];                       # access is "normal"
}                                      # aliasing ends with scope

Note that this is an *alias*, not a *copy*. @ary IS the array, same as
@{ $hash_name->{arrayref} } ... it's just that the anonymous array
referenced by $hash_name->{arrayref} has been given a local() name.
Think of it as a "nickname". =o)

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Reply via email to