I have a text file named cust with 3 fields, time, customer name, location
$ 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
Created a script cust.pl to iterate over each hash
$ cat 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";
}
Getting the following output:
$ ./cust.pl
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
Instead I want the output something like the following. Can you guys please help.
a: 12:10 12:13 : america australia
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.