Subject: | uniq unexpectedly returns its scalar |
Date: | Tue, 5 Feb 2019 11:07:00 +0100 |
To: | bug-Scalar-List-Utils [...] rt.cpan.org |
From: | "Ruud H.G. van Tol" <rvtol [...] isolution.nl> |
When uniq() is entered via goto, it does something undesired:
perl -Mstrict -wE'
use List::Util ();
sub AUTOLOAD {
our $AUTOLOAD;
my $caller_pkg= caller;
my ($sub_pkg, $sub)= ($AUTOLOAD =~ /^(.*)::(.*)/x);
if ( List::Util->can($sub) ) {
my $cref;
{ no strict "refs";
$cref= \&{"List\::Util\::$sub"};
say "\ninjecting $AUTOLOAD";
*$AUTOLOAD= $cref;
}
$ARGV[0] ? goto $cref : return $cref->(@_);
}
die "unknown: $AUTOLOAD";
}
my @data= (-1, 42, 5, 7, 5 );
say "data: @data";
for (1..2) {
say "shuf: @{[ shuffle(@data) ]}";
say "uniq: @{[ uniq(@data) ]}";
}
' 1
data: -1 42 5 7 5
injecting main::shuffle
shuf: 42 7 5 -1 5
injecting main::uniq
uniq: 4
shuf: 7 5 42 -1 5
uniq: -1 42 5 7
-- Greetings, Ruud