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/;
"My two cents aren't worth a dime.";