Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by wfsp (Abbot)
on Nov 23, 2011 at 15:56 UTC ( #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


Comment on Re: How to improve my code? main concern:array as hash element
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2015-07-04 07:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (58 votes), past polls