in reply to a way to do 'sort|uniq'

perl -e 'print sort keys %{{map{$_=>1} <>}}' unsorted_redundant_file.t +xt

See: Perl Idioms Explained - keys %{{map{$_=>1}@list}} in our Tutorials.

Replies are listed 'Best First'.
Re^2: a way to do 'sort|uniq'
by xdg (Monsignor) on Aug 02, 2005 at 18:38 UTC

    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.