Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to accessing elements of reference to hash of arrays by johnguillory

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-26 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found