FAQ

On Jul 30, Paul said:

while (<INPUTFILE>){
if (not $seen{$_}) {
$seen{$_} = 1;
print OUTFILE;
}
else {
}
}
Here's a one-liner:

perl -nle 'print if !$seen{$_}++'

and here's another:

perl -pe '$_ x= !$seen{$_}++' (attributed to some of Larry's genius)

and another, for use in a program

$seen{$_} ||= print OUT while <IN>;

Have fun. :)

--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 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