Skip to content

List::MoreUtils::minmax don't work correctly in some cases. #9

@SandraMeteo

Description

@SandraMeteo

Hello,
When we use the minmax function and all the numbers are the same (min and max must be the same), it returns only the min (max is undef) in some cases.

We have found an example that shows the issue:

use warnings;
use utf8;
use List::MoreUtils qw(minmax);
use Data::Dumper;
use Devel::Peek;

my $valores = [ map { sprintf("%s", 0) } (1..2) ];

my ( $min, $max ) = minmax( map { $_ } @$valores );
print Dumper([$min, $max]);

my @resultados = minmax(  map { $_ } @$valores );
print Dumper(\@resultados);

We get:

```$ perl /tmp/test.pl
$VAR1 = [
          0,
          undef
        ];
$VAR1 = [
          0,
          0
        ];

If we force to use the PP version (pure perl) it works correctly:

```$ export LIST_MOREUTILS_PP=1
$ perl /tmp/test.pl
$VAR1 = [
          0,
          0
        ];
$VAR1 = [
          0,
          0
        ];```
So if we have an intermediate copy, surprisingly it works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions