sunil9009 has asked for the wisdom of the Perl Monks concerning the following question:
Created a script cust.pl to iterate over each hash $ cat cust.pl$ cat cust 12:10 a america 12:11 b bombay 12:12 c calcutta 12:13 a australia 2:30 b bhutan 3:40 n neterland
Getting the following output: $ ./cust.pl#!/usr/bin/perl open FILE1, "cust" or die; my %hash; my %location; while (my $line=<FILE1>) { chomp($line); (my $word1,my $word2, my $word3) = split /\s+/, $line; push (@{$hash{$word2}},$word1); push (@{$location{$word2}},$word3); } for $user (sort keys %hash) { print "$user: @{$hash{$user}} \n"; } for $loc (sort keys %location) { print "$loc: @{$location{$loc}} \n"; }
Instead I want the output something like the following. Can you guys please help.a: 12:10 12:13 b: 12:11 2:30 c: 12:12 n: 3:40 a: america australia b: bombay bhutan c: calcutta n: neterland
a: 12:10 12:13 : america australia
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to iterate over multiple hashes with same key value
by kcott (Archbishop) on Jul 02, 2013 at 06:58 UTC | |
by sunil9009 (Acolyte) on Jul 02, 2013 at 20:01 UTC | |
|
Re: how to iterate over multiple hashes with same key value
by hdb (Monsignor) on Jul 02, 2013 at 06:12 UTC | |
|
Re: how to iterate over multiple hashes with same key value
by Utilitarian (Vicar) on Jul 02, 2013 at 06:21 UTC | |
|
Re: how to iterate over multiple hashes with same key value
by Laurent_R (Canon) on Jul 02, 2013 at 06:28 UTC | |
by hdb (Monsignor) on Jul 02, 2013 at 06:31 UTC | |
by Laurent_R (Canon) on Jul 02, 2013 at 13:33 UTC |