mikejones has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use Data::Dumper; my $test = qq(/etc/skel/test); my ($id,$name,$hash); open (my $test1, "+<", $test) or die "file '$test' was not opened $!"; my (%HoA,$HoA); while(<$test1>) { s/^\s+|\s+$//g; y/^\S|\S$//d; ($id,$name)=split(/\|/,$_); push @{$HoA{$id}}, $name; } print Dumper(\%HoA); for my $i (sort keys %HoA) { print "$i -- @{ $HoA{$i} }\n"; } __DATA__ $ cat -etu test 1|Michael$ 1|Alex$ 1|Bob$ 1|Pete$ 2|Bob$ 2|Andre$ 2|David$ 2|Alex$ 3|Pete$ $ $
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: removing empty lines
by swampyankee (Parson) on May 18, 2007 at 16:15 UTC | |
by mikejones (Scribe) on May 18, 2007 at 17:38 UTC | |
by MonkE (Hermit) on May 18, 2007 at 19:22 UTC | |
by swampyankee (Parson) on May 19, 2007 at 01:05 UTC |