Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: to avoid redundacy in a file

by zejames (Hermit)
on Jul 15, 2002 at 09:34 UTC ( #181726=note: print w/replies, xml ) Need Help??


in reply to to avoid redundacy in a file

One way to do it
# We are modifying the $/ variable, so we limit the scope # by adding some {} around the code { local $/ = ''; $^I = '.bak'; # See man perl and the -i switch for that trick @ARGV = ('data.txt'); while (<>) { # The order is not important, so we sort the fields to # obtain a unique id $sorted = join ':', sort split /\s+/; print if (! $seen{$sorted}++ ); } }

HTH
Update : add comments to the code
--
zejames

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2019-12-15 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?