Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Merging Arrays into a Hash with Substitutions

by broquaint (Abbot)
on Apr 07, 2004 at 16:00 UTC ( [id://343317]=note: print w/replies, xml ) Need Help??


in reply to Merging Arrays into a Hash with Substitutions

A map should do it
while ( my @row = $dbQuery->fetchrow_array() ) { @info{@$headings} = map { defined ? $_ : "" } @row; }
Also, your null filling code is broken, because once a null is found the rest of the values are null because $row[0] doesn't change e.g
my @r = (1, 2, undef, 3, 4); my %h; for(qw/abc def ghi jkl mno/) { if(defined $r[0]) { $h{$_} = shift @r; } else { $h{$_} = ""; } } print Dumper \%h; __output__ $VAR1 = { 'def' => 2, 'abc' => 1, 'mno' => '', 'jkl' => '', 'ghi' => '' };
HTH

_________
broquaint

Log In?
Username:
Password:

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

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

    No recent polls found