in reply to referring to anonymous array in value of a hash in array context...

Unless the array is huge, it's easier to access the values directly through the for loop

$hash{"array"} = ['a','b','c','d','e']; print for @{ $hash{ array } }; a b c d e

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
  • Comment on Re: referring to anonymous array in value of a hash in array context...
  • Download Code

Replies are listed 'Best First'.
Re^2: referring to anonymous array in value of a hash in array context...
by Fletch (Bishop) on Jul 08, 2004 at 01:34 UTC

    Actually the size of the array shouldn't matter because when foreach gets a real array perl will be smart and won't expand things in place (it uses an iterator over the AV* behind the scenes which all happens in C underneath).

    $ perl -MBenchmark=timethese -e <<'EOC' $a = [ 0 ..5_000 ]; timethese( 2_000, { index => sub { for( my $i = 0; $i <= $#{ $a }; $i++ ) { $b = $a->[ +$i] } }, iterator => sub { for( @{ $a } ) { $b = $_ } } } ) EOC Benchmark: timing 2000 iterations of index, iterator... index: 27 wallclock secs (21.21 usr + 0.02 sys = 21.23 CPU) @ 94 +.21/s (n=2000) iterator: 6 wallclock secs ( 5.39 usr + 0.00 sys = 5.39 CPU) @ 37 +1.06/s (n=2000)