in reply to Collapsing a string to unique characters
In existing order:
perl -nle"my %seen; print grep !$seen{$_}++, /./g"
In lexical order:
perl -nle"my %seen; print sort grep !$seen{$_}++, /./g"
By the way, the chomp is useless because -nl already chomps.
>perl -MO=Deparse -nle"foo()" BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = <ARGV>)) { chomp $_; foo(); } -e syntax OK
Update: Oops, I had my tests inverted. Fixed.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Collapsing a string to unique characters
by dwhite20899 (Friar) on Jan 09, 2009 at 14:17 UTC | |
|
Re^2: Collapsing a string to unique characters
by dwhite20899 (Friar) on Jan 09, 2009 at 14:21 UTC |