Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: iterate through a hash with two keys

by BillKSmith (Chaplain)
on Apr 30, 2013 at 02:12 UTC ( #1031299=note: print w/ replies, xml ) Need Help??


in reply to Re^2: iterate through a hash with two keys
in thread iterate through a hash with two keys

This may be what you want.

use strict; use warnings; my $label1 = 'L1'; my $label2 = 'L2'; my %hash; @hash{'a' .. 'h'} = ( {$label1 => 1 }, {$label1 => 2 }, {$label2 => 3 }, {$label1 => 4 }, {$label2 => 5 }, {$label1 => 6 }, {$label2 => 7 }, {$label1 => 8 }, ); while ( my( $key,$subhash ) = each %hash) { print "$key: $subhash->{$label1}\n" if exists $subhash->{$label1}; }
OUTPUT:
a: 1 d: 4 h: 8 b: 2 f: 6
Bill


Comment on Re^3: iterate through a hash with two keys
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-08-20 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (105 votes), past polls