[sf-perl] Sort subroutine didn't return single value at -e line 1.
Bill Moseley
moseley at hank.org
Fri Apr 5 15:13:58 PDT 2013
On Fri, Apr 5, 2013 at 2:46 PM, Uri Guttman <uri at stemsystems.com> wrote:
>
> sort takes a sub name for its first arg if that is a bareword. so you are
> sorting the whole list but using uniq as the comparison function.
>
> try putting parens around the list so uniq looks like a sub. or parens
> around uniq and the list but that is wrong because sort defaults to alpha
> sorting and that will only work on numbers of the same length.
Oh, I had tried parens, but I guess it's still seen as a barword.
$ perl -wle 'use Data::Dumper; use List::MoreUtils "uniq"; print Dumper
[sort uniq( 3,1,3,2)]'
$VAR1 = [
1,
2,
3,
3
];
as well as "sort (uniq 3,1,3,2)"
Does the plus sign tell sort it's not a bareword in this case?
$ perl -wle 'use Data::Dumper; use List::MoreUtils "uniq"; print Dumper
[sort +uniq 3,1,3,2]'
$VAR1 = [
1,
2,
3
];
Yes, still need to deal with the numeric sort, but I was just using that
list as an example.
--
Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20130405/aacaacd3/attachment.html>
More information about the SanFrancisco-pm
mailing list