Subject: | listcmp behaviour mismatch (between XS and PP, and to the doc) |
I noticed that contrary to what the manual seems to say, in scalar context, listcmp does not return what we would think it does.
Here's the doc:
my $cmp = listcmp @seq, @prim, @fib;
# returns { 1 => [0, 2], 2 => [0, 1, 2], 3 => [0, 1], 5 => [1] }
i.e. it supposedly returns a hashref (in place of the plain hash in list context).
Attached is a short script to test this behaviour. Here is its output:
List::MoreUtils::XS version is: 0.428
List::MoreUtils::PP version is: 0.428
[XS]
$\%cmp = {
'1' => [
0,
1
],
'3' => [
0,
1
],
'2' => [
0,
1
]
};
$cmp = [
0,
1
];
[PP]
$\%cmp = {
'3' => [
0,
1
],
'1' => [
0,
1
],
'2' => [
0,
1
]
};
$cmp = 3;
In both cases the hashes are correct, and the scalar context values are not, in neither case is it a hashref, and they also differ from each other.
Subject: | moreutils-listcmp.pl |
#!/usr/bin/perl
use v5.26;
use Data::Dumper;
use List::MoreUtils::XS;
use List::MoreUtils::PP;
my @a = (1,2,3);
my @b = (3,1,2);
say "List::MoreUtils::XS version is: $List::MoreUtils::XS::VERSION";
say "List::MoreUtils::PP version is: $List::MoreUtils::PP::VERSION";
say "[XS]";
my %cmp = List::MoreUtils::XS::listcmp(@a, @b);
my $cmp = List::MoreUtils::XS::listcmp(@a, @b);
print Data::Dumper->Dump([\%cmp, $cmp], ['\%cmp', '$cmp']);
say "[PP]";
my %cmp = List::MoreUtils::PP::listcmp(@a, @b);
my $cmp = List::MoreUtils::PP::listcmp(@a, @b);
print Data::Dumper->Dump([\%cmp, $cmp], ['\%cmp', '$cmp']);