in reply to Re: output unique lines only
in thread output unique lines only

Thanks everyone for their tips/suggestions. I've decided to approach this using a hashtable.
I came up with the following script but it doesn't seem to be working correctly.
#!/usr/bin/perl -w $filelist = "/home/exp/acctlist.txt"; open(FILEDUPS, $filelist) || die ("Cannot open $filelist"); open($output, '>', '/home/exp/output.txt') || die ("Cannot open file"); while ($line = <FILEDUPS>) { chomp $line; ($filename, undef, undef, undef, undef) = split /\t/, $line; } $uniquefiles{$filename} = 1; foreach $k (keys %uniquefiles) { print $output "$k\n"; }
It currently only outputs one line. For example, if my file contains
filename1
filename2
filename1
filename4

Then it outputs the first line only:
filename1
Where as it should output:
filename1
filename2
filename4

I've spent a long time trying to debug this, but i'm not sure where i'm going wrong.
Thanks.

Replies are listed 'Best First'.
Re^3: output unique lines only
by kulls (Hermit) on Dec 07, 2005 at 04:11 UTC
    hi,
    I guess you should give the  $uniquefiles{$filename} = 1; inside the while loop.
    -kulls