Noam beat me to it, but here's perl solution without additional variables:
#!/usr/bin/perl
%hash = (a=>['moo','goo','woo'],
foo=>3,
baz=>5);
$ref = \%hash;
foreach my $elem (@{$ref->{a}})
{
print "$elem\n";
}
Regards,
Dov
2009/10/24 Shachar Shemesh <[email protected]>
> Hi all,
>
> $ref is a reference to a hash. Hash contains a component called "a" which
> is an array. I would like to iterate all elements of said array.
>
> I would like to do something along the lines of:
> foreach my $elem @%$ref{a}
> {
> print "$elem\n";
> }
>
> Which, I think it clear, does not work. I also tried:
> foreach my $elem @(%$ref){a}
> {
> print "$elem\n";
> }
>
> which complains about:
> Bareword "a" not allowed while "strict subs" in use
>
> and:
> foreach my $elem @(%$ref){'a'}
> {
> print "$elem\n";
> }
>
> which complains about:
> Global symbol "$elem" requires explicit package name at line 3 (i.e. -
> inside the for).
>
> Any help would be appreciated.
>
> Thanks,
> Shachar
>
> --
> Shachar Shemesh
> Lingnu Open Source Consulting Ltd.http://www.lingnu.com
>
>
> --
> Shachar Shemesh
> Lingnu Open Source Consulting Ltd.http://www.lingnu.com
>
>
> _______________________________________________
> Linux-il mailing list
> [email protected]
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>
>
_______________________________________________
Linux-il mailing list
[email protected]
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il