John W. Krahn wrote:
country wrote:
[snip]
Notice in File OUT for Server Name (wsompapgtw05),
since wsompapgtw05 does not appear in File A, the
value is replaced with '0'. How can I get perl to
place a '0' in the output file when a particular
server name appears in at least 1 of the input files,
but not in all of the input files?
This appears to do what you want:
@ARGV = glob 'File[ABC]';
my %resultacpu;
my $column = 0;
while ( <> ) {
next if $. == 1; # skip header line
my ( $server, $cpua ) = split /,/;
$resultacpu{ $server }[ $column ] = $cpua;
if ( eof ) {
$column++;
close ARGV;
}
}
open my $nfh, '>', 'OUT' or die "Can't open 'OUT' $!";
for my $server ( sort keys %resultacpu ) {
print $nfh join( ',', map $_ || 0, $server, @{ $resultacpu{ $server
} } ), "\n";
}
close $nfh or die "Can't close 'OUT' $!";
John,
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.
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/