Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How to improve my code? main concern:array as hash element

by wfsp (Abbot)
on Nov 23, 2011 at 15:56 UTC ( [id://939690]=note: print w/replies, xml ) Need Help??


in reply to How to improve my code? main concern:array as hash element

You probably need
my %gp = ( ... Gi => \@gi, # an array ref Gt => \@gt, );
Hash values can only be scalars. An array reference is a scalar so we can use that.

In your while loop you will first need to test if it is an array ref and, if so, dereference it. Something like

... $j = $gp{$i}; my @values; if (ref $j eq 'ARRAY'){ @values = @{$gp{$i}}; } else { @values = ($j); } for $val (@values){ ...
(not tested)
update: fixed typo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://939690]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found