in reply to Re^2: Delete Duplicate Entry in a text file
in thread Delete Duplicate Entry in a text file
Without having changed your code too much
It could stand a bit more changing though.
Why use s/// and why the /g if you do? If you are going to do it, chomp $line; is preferable. Now what if the line is "0\n"? Zero is false. Contrived? Okay... then what if the line contains some whitespace before the newline? Whitespace is true. Checking for the truth of !$line isn't really what you mean. You want to skip $line unless it contains a non-whitespace character so just say what you mean:$line =~ s/\n//g; next if !$line;
No need to change the line and no need to re-append the newline later.next unless $line =~ /\S/;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Delete Duplicate Entry in a text file
by Kenosis (Priest) on Jun 20, 2012 at 18:44 UTC | |
by sauoq (Abbot) on Jun 21, 2012 at 00:23 UTC | |
by Kenosis (Priest) on Jun 21, 2012 at 04:09 UTC |