in reply to hash table with three input files
my %prices; # read all files: for $fn (@files){ open (my $file, '<', $fn) or die "Can't open '$fn' for reading: $!" +; while (<$file>){ chomp; my @items = split m/;/, $_; push @{$prices{$items[0]}, $items[1]; } } # print output: for my $k (sort keys %prices){ print "$k;", join(';', @{$prices{$k}}), $/; }
This works for an arbitrary number of files, but if some prices are only present in some files, the result doesn't show which prices comes form which file.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash table with three input files
by steph_bow (Pilgrim) on Feb 12, 2008 at 13:50 UTC |