Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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 examining the Monastery: (10)
As of 2014-11-29 00:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (200 votes), past polls