FAQ

--- Jeff 'japhy/Marillion' Pinyan wrote:
perl -pe '$_ x= !$seen{$_}++' (attributed to some of Larry's genius)
LOL!!! Twistedly brilliant!

Ok, lemme see if I can parse this.....

perl -pe says print each line after the -e code has been executed.

"$_ x= !$seen{$_}++" says:

$_ x=
assign to $_ itself, repeated a number of times

!$seen{$_}
evaluate $seen{$_} in a negated boolean context for the number

postfix ++ increments after returning the previous value.

so "$_ x= !$seen{$_}++" says

1) check $seen{$_} (have we seen this before)
2) then increment it (we've seen it now!)
3) negate the boolean value of $seen{$_} from before the increment
4) assign $_ to itself a number of times equal to the boolean return
(i.e., 0 or 1)

Then -p prints $_, which is either what it was before, or ''
(repetition zero times!)

Is that right?

LOL!!! That's truly, beautifully, perversely thick! >:O]

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

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

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