Truly astounding.

From: Paul
--- David Blevins wrote:
perl -nle 'print if !$seen{$_}++'

Tries to lookup the line in the hash of lines we've already seen.


This is a complete guess, I can't seem to find anything like this in
the 'Programming Perl' book.
It's just a postfix increment on the value in %seen as looked up using
$_ as the key. You've got the idea.
So the command not only weeds out the duplicate lines, it counts as well!
That's great! I hate to even think of how many lines in java it would take
to do the same thing. It takes on line just to create the hash.
I love Perl. =o)

Of course, writing readable code is always a good idea, but explaining
*tight* code is a great learning experience! lol!
I am a very accomplished java programmer and many aspects of programming are
just old news. I really have zero need to learn another language in my
professional career. But since I've ran across Perl, I've found so many new
ways to do things that were just old hat -- I just have to learn it. Perl
takes something I've been doing for years and makes it new again.


Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 11 of 16 | next ›
Discussion Overview
groupbeginners @
postedJul 30, '01 at 6:15p
activeJul 30, '01 at 9:40p



site design / logo © 2022 Grokbase