Hello, The following code successfully prints all content of a hash of arrays:
for $x ( keys %HoA ) {
print "$x: ";
for $i ( 0 .. $#{ $HoA{$x} } ) {
print "$HoA{$x}[$i] ";
}
}
Output looks like this:
Keys: array
8001: bp ne sc ax br le no ns mn sl lt sh lw ni lu dl
5022: bp ne sc ax br le no ns mn sl lt sh lw ni lu dl
1018: bp ne br no lt lw ni l
I pass the %HoA to a function and want to print all the elements of th
+e %HoA—but I’m failing to do this inside the function. This is my pro
+blem. (The same function that receives the HoA must also process an
+array. )
some_function(\%HoA); # could be some_function(\@array)
sub some_function{
$aref = shift;
if (ref($aref) eq “ARRAY”){
Do something with array---I got this muchworking!
} elsif (ref($aref) eq “HASH”){
#This foreach of the hash ref doesn't print anything!
foreach $key ( keys %{$aref} ){
print “key: $key…..”;
for ( $i = 0; $i <=100; $i++ ){
print “ $aref->{$key}[$i] “;
}
}
Thanks for any clues.
John
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|