Thank you for your thoughts. My intent was to produce the OP's requested output w/o doing too much to the original code for the sake of a differentiated learning experience.
I tried your suggestions as follows on the OP's data set:
use Modern::Perl; my $lastrow = ""; open my $fh, '<', 'fail.txt' or die $!; while (my $line = <$fh>) { next unless $line =~ /\S/; if ($line ne $lastrow) { print $line; $lastrow = $line; } } close $fh;
Output:
hostname1.com Gateway FAIL hostname2.com Gateway FAIL Gateway FAIL
Unless I've misunderstood your re-coding suggestions, they do not produce the OP's desired outcome. (Using say instead of print produces the desired line spacing, but the last string is repeated.)
In reply to Re^4: Delete Duplicate Entry in a text file
by Kenosis
in thread Delete Duplicate Entry in a text file
by astronogun
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |