Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: looping through a hash and looking up values from another hash

by BillKSmith (Monsignor)
on Apr 26, 2017 at 16:18 UTC ( [id://1188979]=note: print w/replies, xml ) Need Help??


in reply to looping through a hash and looking up values from another hash

This approach handles all the lines.
use strict; use warnings; my %hash1 = ( 1 => [qw( You Me Him Her )], 2 => [qw( fie fii foo fum )], 3 => [qw( aaa bbb ccc ddd )], ); my %hash2 = ( 1 => 3, 51 => 0, 32 => 1, ); foreach (sort keys %hash1){ local( $,, $\) = ("\t", "\n"); print @{ $hash1{$_} }, exists $hash2{$_} ? $hash2{$_} : q(); } OUTPUT: You Me Him Her 3 fie fii foo fum aaa bbb ccc ddd
Bill
  • Comment on Re: looping through a hash and looking up values from another hash
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-19 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found