in reply to duplicate lines

Grrrrr the "solution" listed below is wrong. It removes adjacent duplicate lines. This is not what the requestor was asking. See the reponses from the other monks for a useful solution.

If you're on a Unix system you can just `uniq` the file. But if you must do it in Perl . . .

my $lastline; while(<>) { print if $lastline ne $_; $lastline = $_; }
Be Appropriate && Follow Your Curiosity

Replies are listed 'Best First'.
Re^2: duplicate lines
by Tomtom (Scribe) on Jun 02, 2005 at 11:26 UTC
    I'm not sure your solution works if the duplicate entries aren't on following each other :

    line 1 : "toto"
    line 2 : "titi"
    line 3 : "toto"

      You're right, I misread the problem. I was thinking of repeated lines, not duplicates.

      Be Appropriate && Follow Your Curiosity