david2008 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
This is a crosslist from
stack overflow
The problem is the following
sort +uniq @letters;
What does the + mean?
Thanks,
David
gives as outputuse strict; use List::MoreUtils qw/uniq/; use Data::Dumper; my @x = (3,2); my @y = (4,3); print "unique results \n"; print Dumper([uniq(@x,@y)]); print "sorted unique results\n"; print Dumper([sort uniq(@x,@y)]);
unique results $VAR1 = [ 3, 2, 4 ]; sorted unique results $VAR1 = [ 2, 3, 3, 4 ];
Unfortunately the uniq does not work anymore.
There is an answer from amon that perl uses the sort function form where the first parameter is a function and the second a list, but i still don't understand why it does not execute uniq beforehand and then uses the sort LIST,instead of preferring the sort SUBNAME LIST form.
sort +uniq @letters;
What does the + mean?
Thanks,
David
Back to
Seekers of Perl Wisdom