FAQ

--- Carl Rogers wrote:
One word of caution.... it looks to me like this will catch
duplicates lines, just as long as the duplicate lines follow each
other. . . . <snip>
I posted a one-liner that does the same as the code below. =o)
while (<INPUTFILE>){
if (not $seen{$_}) {
$seen{$_} = 1;
print OUTFILE;
}
else {
}
}

I wish I could tell you why/how it works (I'm *still* working my way
up to newbie status), but it does. (Magic??)..
Not magic. =o)
the code above says:
while (<INPUTFILE>){
reads a line of the file into $_
if (not $seen{$_}) {
checks a global hash called %seen for a key equal to $_
(the line just read). If it WASN'T already in the hash
(in other words, we haven't %seen it =o) . . .
$seen{$_} = 1;
print OUTFILE;
}
then PUT it in the hash, and print the record.
else {
}
}
Otherwise, we've already printed it when we put it in the hash,
so do nothing.

Paul ;o]

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 16 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedJul 30, '01 at 6:15p
activeJul 30, '01 at 9:40p
posts16
users6
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase