<div dir="ltr">Noam beat me to it, but here's perl solution without additional variables:<br><br><span style="font-family: courier new,monospace;">#!/usr/bin/perl</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">%hash = (a=>['moo','goo','woo'],</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> foo=>3,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> baz=>5</span><span style="font-family: courier new,monospace;">);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">$ref = \%hash;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">foreach my $elem (@{$ref->{a}})</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> print "$elem\n";</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br><br>Regards,<br>Dov<br><br><div class="gmail_quote">2009/10/24 Shachar Shemesh <span dir="ltr"><<a href="mailto:shachar@shemesh.biz">shachar@shemesh.biz</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr" bgcolor="#ffffff" text="#000000">
Hi all,<br>
<br>
$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.<br>
<br>
I would like to do something along the lines of:<br>
foreach my $elem @%$ref{a}<br>
{<br>
print "$elem\n";<br>
}<br>
<br>
Which, I think it clear, does not work. I also tried:<br>
foreach my $elem @(%$ref){a}<br>
{<br>
print "$elem\n";<br>
}<br>
<br>
which complains about:<br>
Bareword "a" not allowed while "strict subs" in use<br>
<br>
and:<br>
foreach my $elem @(%$ref){'a'}<br>
{<br>
print "$elem\n";<br>
}<br>
<br>
which complains about:<br>
Global symbol "$elem" requires explicit package name at line 3 (i.e. -
inside the for).<br>
<br>
Any help would be appreciated.<br>
<br>
Thanks,<br>
Shachar<br>
<pre cols="72">--
Shachar Shemesh
Lingnu Open Source Consulting Ltd.
<a href="http://www.lingnu.com" target="_blank">http://www.lingnu.com</a>
</pre>
<br>
<pre cols="72">--
Shachar Shemesh
Lingnu Open Source Consulting Ltd.
<a href="http://www.lingnu.com" target="_blank">http://www.lingnu.com</a>
</pre>
</div>
<br>_______________________________________________<br>
Linux-il mailing list<br>
<a href="mailto:Linux-il@cs.huji.ac.il">Linux-il@cs.huji.ac.il</a><br>
<a href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il" target="_blank">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a><br>
<br></blockquote></div><br><div style="display: none;" id="divCleekiAttrib"></div></div>