The code as you have written, does not have balanced { braces }, so I can't see how far you got. Nor is it indented in a way that makes clear what loop the continue statement belongs to. Trying to fix it, I have some comments: Better than
my ($server, @data) = (split(“,”,$line));
would be
my ($server, $data) = (split(“,”,$line));
or even better would be
my ($server, $data) = split ',', $line, 2;
Actually this last addition of the 2 argument doesn't make too much difference since perl already optimizes this, and stops without parsing the whole line. Note also that none of the parentheses were needed on the right hand side.

Now with a simple scalar data, it is easier to fix the code that you have to skip the first line, so instead of

if ($data[0] lt “!” ) { $data[0] = 0; } next if grep /[^0-9.]/, @data;
you could try
next if $data =~ /[^0-9.]/;
Furthermore, you did a clever
push @{$usage{$server}}, 0 while @{$usage{$server}} < $files; push @{$usage{$server}}, $data[0];
But perl already autoextends arrays, so you can simply write
$usage{$server}->[$files] = $data unless $usage{$server}->[$files]
This will leave all the previous zeros as missing, which you can deal with at the end more easily. BTW, your code will fill in missing zeros, if the are followed by data in later files, but if the missing zeros were in the third file, the arrays would not receive the zeros using your code.

At the end you have

continue { $files++ if eof; } close $fh or die "Can’t close file $file: $!";
What is the point? Why not a clean
my $files = 0; for my $file ("sfull1ns.dat","sfull2ns.dat","sfull3ns.dat") { open (my $fh,'<',$file) or die "Can’t open file $file: $!"; while (my $line = <$fh>) { ... } $files++ close $fh or die "Can’t close file $file: $!"; }

And you have no provision for output, obviously you need a final line after the whole looping is done which does

print "$_," . (join ',', @{$usage{$_}}) . "\n" for (keys %usage);

This will of course complain about uninitialized values in the array, but will run. Instead of zeros, the missing values will be missing, but we are nearly there. So now is the time to fix that by putting this code just before the printout.

for (keys %usage) { for my $f (0,1,2) { $usage{$_}->[$f] = 0 unless defined $usage{$_}->[$f]; } }
You may argue that your solution was better, keeping this inside the main loop. It did take less code. But it was confusing in the middle of other processing. Here, to separate it out, in my mind makes cleaner code.

I have not put it all together for you, so that you can understand each piece as you implement it, but it did work for me.


In reply to Re: Eliminating Duplicate Lines From A CSV File by b4swine
in thread Eliminating Duplicate Lines From A CSV File by country1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.