Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Errors on loops over data

by EvanCarroll (Chaplain)
on Sep 16, 2009 at 17:44 UTC ( [id://795676]=note: print w/replies, xml ) Need Help??


in reply to Errors on loops over data

I'm not sure /why/ you want to assign to $h{undef} which is what your trying, my best suggestion would be to explicitly use $h{ $val // '__NOT PRESENT__' } in perl 5.10. This still leaves it as an exercise to the reader, on what to do when you have two undefs you want to save too...
This is pseudo-data, which probably doesn't represent a real world problem very well. My fix would be to skip over the undef vals.
foreach my $d(@data){ my %h; foreach my $c(0 .. $#categories){ my $val=$d->[$c]; next unless defined $val; my $cat=$categories[$c]; $h{$val}=$cat; } push @master, \%h; }


Evan Carroll
The most respected person in the whole perl community.
www.EvanCarroll.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found