in reply to Re: Eliminating Duplicate Lines From A CSV File
in thread Eliminating Duplicate Lines From A CSV File


GrandFather,


The CSV files I am using for input are actually much
larger (1600 + records each). How can I modify your
code to read the 3 input files ("sfull1ns.dat",
"sfull2ns.dat", and "sfull3ns.dat") from disk rather
than instream?

  • Comment on Re^2: Eliminating Duplicate Lines From A CSV File

Replies are listed 'Best First'.
Re^3: Eliminating Duplicate Lines From A CSV File
by GrandFather (Saint) on Jul 25, 2007 at 21:03 UTC

    Is this what you want?

    use strict; use warnings;
    my %usage; my @files = qw(sfull1ns.dat sfull2ns.dat sfull3ns.dat); for my $file ( @files ) { open( my $fh, "<", $file ) or die "Can't open file $file: $!"; <$fh>; # Skip header line while ( my $line = <$fh> ) { chomp($line); my ( $server, @data ) = ( split( ",", $line ) ); $usage{$server}{$file}{value} ||= $data[0]; } } for my $file (@files) { $usage{$_}{$file}{value} ||= 0 for keys %usage; } for my $server (sort keys %usage) { print "$server,", join (',', map {$usage{$server}{$_}{value}} sort keys %{$usage +{$server}}), "\n"; }

    DWIM is Perl's answer to Gödel