Perl question: array member of referenced hash

Perl question: array member of referenced hash

Shachar Shemesh shachar at shemesh.biz
Sat Oct 24 19:24:07 IST 2009


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20091024/fbdeacc0/attachment-0001.html>


More information about the Linux-il mailing list