Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Removing repeated lines from file

by Tomte (Priest)
on Jun 24, 2003 at 11:39 UTC ( [id://268458]=note: print w/replies, xml ) Need Help??


in reply to Removing repeated lines from file

You only have to remember the last unique-line, a shot from the hip (untested!):

open(FILE, "<", name.ext") or die("couldn't open file: $!"); open(OUT, ">", new.ext") or die("couldn't open file for writing: $!") +; my $cmp = <FILE>; # the first line print OUT $cmp; # is always unique while(<FILE>) { if ($_ ne $cmp) { # current line unlike last one? print OUT $_; # print it out $cmp = $_; # current line new reference } # otherwise ignore }

regards,
tomte


Hlade's Law:

If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://268458]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-29 13:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found