On 7/18/07, Rob Dixon <[EMAIL PROTECTED]> wrote:
snip
Your solution has the same problem that made my final one frustratingly
ugly: if a server name is missing from the last file in the list there
will be no corresponding trailing zero in the output file for that server.
snip

The answer is to use a HoH instead of a HoA.  This lets you use a hash
slice to ensure that every file is represented.  Files that don't have
a given server will return undef and a simple map will turn the undef
values into 0s.  You can also shave away some of the code by
integrating the split and the check into one regex.

#!/usr/bin/perl

use strict;
use warnings;

local @ARGV = qw/ fileA.txt fileB.txt fileC.txt /;

my @files = @ARGV;
my %usage;
while (<>) {
       next unless /(\w+),([\d.]+)(?:,|$)/;
       $usage{$1}{$ARGV} = $2;
}

for my $k (sort keys %usage) {
       print join(",", $k, map {$_ or 0} @[EMAIL PROTECTED]), "\n";
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to