Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Print something when key does not exist

by NetWallah (Canon)
on Apr 06, 2014 at 04:51 UTC ( [id://1081287]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Print something when key does not exist
in thread Print something when key does not exist

++ for asking good questions.

Yes the !@F handles blank lines. When split, these will leave the @F array unpopulated, so scalar(@F) will be 0, or false, and the line gets skipped.

The %h is a Hash of Hashes. the outer "for sort keys %h" handles the first (outer) hash.
Inside that, I use a "hash slice" to get an array of values for keys specified by @w (which is a sorted array).

This is pretty much the same thing kcott does in his line:

map { $data{$name}{$_} || '' } @codes;
except - my code does not worry about non-existing keys - since I run without 'warnings', my code does the right thing without complaint.

        What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
              -Larry Wall, 1992

Replies are listed 'Best First'.
Re^4: Print something when key does not exist
by jaypal (Beadle) on Apr 06, 2014 at 06:15 UTC

    Thanks so much for your prompt response. Hash slice looks really handy. It effectively eliminated the need for two for loops I have in my answer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-24 06:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found