in reply to Elegant way to dereference an array or hash?

The methods above make COPIES of the array.

It is possible (but not necessarily a good idea) to avoid that, using Typeglobs:

my $foo = {bar=>{baz=> [3,4,5,6]}}; local *baz= $foo->{bar}{baz}; # typeglob ALIAS, not a copy print qq(@baz);
The obscurity vs efficiency of this kind of code might be a worthwhile tradeoff if run frequently, and/or with large arrays, when used correctly, and documented.

    Earth first! (We'll rob the other planets later)

Replies are listed 'Best First'.
Re^2: Elegant way to dereference an array or hash?
by waswas-fng (Curate) on Nov 17, 2004 at 01:23 UTC
    I have worked on tons of legacy code that used typeglobs in this way, one thing I can suggest is a var prefix that is standardized across the codebase. It makes it a lot easier to trace things out if you are looking at $tgl_varname or some such vs $randomname when the typeglob alias is created half way across a large sub or file. Also IMHO the long form deref is better all around as it does not introduce one more var name to keep track of in my tiny head.


    -Waswas