Skip Menu |
 

This queue is for tickets about the List-MoreUtils CPAN distribution.

Report information
The Basics
Id: 82039
Status: resolved
Priority: 0/
Queue: List-MoreUtils

People
Owner: Nobody in particular
Requestors: BitCardJade.5.JadeNB [...] spamgourmet.com
MMIMS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 0.33
  • 0.33_005
Fixed in: 0.408



Subject: Carp::croak must be predeclared; uniq stringifies while filtering
Download (untitled) / with headers
text/plain 434b
The following code: --- use List::MoreUtils qw/uniq/; my $a = []; print ( uniq $a, "$a" ), "\n" --- prints out a 1-entry list, whereas it should produce a 2-entry list. This is because the uniq filter stringifies. The attached diff fixes this in the pure-Perl version, as well as remedying an error where 2 occurrences of Carp::croak threw an error (because they were compiled before the corresponding require Carp was executed).
Subject: no-stringify.patch
Download no-stringify.patch
text/x-diff 510b
--- MoreUtils.pm 2008-11-20 11:54:40.000000000 -0500 +++ /Volumes/LS1/lspice/.perl/lib/perl5/darwin-2level/List/MoreUtils.pm 2006-07-02 11:26:35.000000000 -0400 @@ -218,8 +218,6 @@ return each_arrayref(@_); } -sub Carp::croak; - sub each_arrayref { my @arr_list = @_; # The list of references to the arrays @@ -282,7 +280,7 @@ sub uniq (@) { my %h; - map { $h{ ref $_ ? 'r' . $_ : 's' . $_ }++ == 0 ? $_ : () } @_; + map { $h{$_}++ == 0 ? $_ : () } @_; } sub minmax (@) {
From: BitCardJade.5.JadeNB [...] spamgourmet.com
Sorry, the patch file was reversed. I attach a correct version.
Download no-stringify.patch
text/x-diff 510b
--- /Volumes/LS1/lspice/.perl/lib/perl5/darwin-2level/List/MoreUtils.pm 2006-07-02 11:26:35.000000000 -0400 +++ MoreUtils.pm 2008-11-20 11:54:40.000000000 -0500 @@ -218,6 +218,8 @@ return each_arrayref(@_); } +sub Carp::croak; + sub each_arrayref { my @arr_list = @_; # The list of references to the arrays @@ -280,7 +282,7 @@ sub uniq (@) { my %h; - map { $h{$_}++ == 0 ? $_ : () } @_; + map { $h{ ref $_ ? 'r' . $_ : 's' . $_ }++ == 0 ? $_ : () } @_; } sub minmax (@) {
Subject: uniq changes the type of its arguments
Download (untitled) / with headers
text/plain 472b
There's a subtle problem with the implementation of uniq. The use of $_ as the key to %seen changes the the type of numeric arguments to strings. Observe: $ perl -MJSON::Any -E 'say JSON::Any->encode([ do { grep { not $seen{$_}++ } 1, 2, 2, "3", 4 } ])' ["1","2","3","4"] It can be fixed by assigning to a temporary in grep's code block: $ perl -MJSON::Any -E 'say JSON::Any->encode([ do { grep { my $v = $_; not $seen{$v}++ } 1, 2, 2, "3", 4 } ])' [1,2,"3",4] -Marc
Added PP fix in 51ab372 (XS during introduction of singleton in 9d12b62).
Beside the import of croak, it's (earlier but hidden behind a weird subject) the same as #82039


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.