in reply to Re: a way to do 'sort|uniq'
in thread a way to do 'sort|uniq'
Perl Idioms Explained - keys %{{map{$_=>1}@list}} does caveat that this may not be appropriate for large lists. If that's a concern with the input being processed, the same thing can be done in line-by-line fashion.
perl -e '$seen{$_} = 1 while <>; print sort keys %seen' input.txt
The article has some good commentary. For example, this approch above is slowest. Faster is this with $seen{$_} = undef, the grep approach is faster still, and the slice approach is apparently even faster.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|
|---|