On Wed, May 02, 2001 at 11:11:20AM -0700, Paul wrote:
: 
: --- "M.W. Koskamp" <[EMAIL PROTECTED]> wrote:
: > > : open FH, "lines.txt" || die $!;
: > > : my %uniq;
: > > : map{$uniq{$_}=1 and print $_ unless $uniq{$_} }<FH>;
: 
: lol -- one better(ish....):
:  print map { $uniq{$_} ? '' : $uniq{$_}=$_ } <FH>; #:op

  perl -pe'$_=""if$f{$_}++' file

or

  print grep { ! $uniq{$_}++ } <DATA>;

grep will loop over a list and, if the block ( it's firt argument ) is
true, it will return the element in the list.  The above will loop
over lines in a file and it will return the line if the value of the
key pertaining to the line in %uniq is NOT true.  Post-increment gets
evaluated at the very end of a statement so the first time 'foo' is
seen, $uniq{foo} is false when the condition is checked and set to
true right afterward.  It remains true for the rest of the grep.

Please take anything further to Fun With Perl or personal email,
unless you are willing to explain your code, please?!

  Casey West

-- 
"Eat a live toad first thing in the morning and nothing worse will
happen to you the rest of the day"
 --Unknown

Reply via email to