I have the following script:
use strict;
use List::MoreUtils qw/uniq/;
use Data::Dumper;
my @x = (3,2);
my @y = (4,3);
print "unique results
";
print Dumper([uniq(@x,@y)]);
print "sorted unique results
";
print Dumper([sort uniq(@x,@y)]);
The output is
unique results
$VAR1 = [
3,
2,
4
];
sorted unique results
$VAR1 = [
2,
3,
3,
4
];
So it looks that sort does not work with uniq.
I did not understand why.
I ran the perl script with -MO=Deparse and got
use List::MoreUtils ('uniq');
use Data::Dumper;
use strict 'refs';
my(@x) = (3, 2);
my(@y) = (4, 3);
print "unique results
";
print Dumper([uniq(@x, @y)]);
print "sorted unique results
";
print Dumper([(sort uniq @x, @y)]);
My interpretation is that perl decided to remove the parentheses from uniq(@x,@y) and using uniq as a function of sort.
Why did perl decide to do it?
How can i avoid these and similar pitfalls?
Thanks,
David
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…