Re: removing duplicates
- From: Jenda@xxxxxxxxxxx (Jenda Krynicky)
- Date: Wed, 30 Apr 2008 13:53:59 +0200
From: "John W. Krahn" <krahnj@xxxxxxxxx>
Jenda Krynicky wrote:
From: "John W. Krahn" <krahnj@xxxxxxxxx>
Rob Dixon wrote:
obdulio santana wrote:Or the shortness of:
May be this helpsYou may prefer the cuteness of
perl -lne "print if ++$D{$_} == 1" address.txt
perl -lne "print unless $D{$_}++" address.txt
perl -ne'$D{$_}++||print' address.txt
Actually this
perl -n'${$_}||=print'
works as well as long as the last line in the file either does end
with a newline or doesn't match any builtin variable whose default
value is already true.
One more keystroke down.
$ perl -c -n'$D{$_}++||print'
Unrecognized switch: -$D{$_}++||print (-h will show valid options).
Sorry, it should have been
perl -ne'${$_}||=print'
I'm using windows so I have to test it with doublequotes in place of
the singlequotes so I must have made a mistake changing them back.
From: "Chas. Owens" <chas.owens@xxxxxxxxx>
That is nasty. If I am reading that correctly you are using a
symbolic reference to create variables with the name of the line. > I can't remember, does Perl have a limit on the size of a variable > name?
Yes, you are reading it correctly. And since the line contains the
newline it can't match any builtin. Except possibly for the last line
in the file.
Does it have a limit on the size of a hash key?
If it does, then the limit is high enough I believe.
Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
.
- References:
- Re: removing duplicates
- From: Jenda Krynicky
- Re: removing duplicates
- From: John W. Krahn
- Re: removing duplicates
- Prev by Date: Re: perl source code encryption
- Next by Date: Re: I want a perl script for?
- Previous by thread: Re: removing duplicates
- Next by thread: Re: removing duplicates
- Index(es):
Relevant Pages
|
|