larard has asked for the wisdom of the Perl Monks concerning the following question:

I was wondering about the following behaviour, and couldn't explain it.
$ perl -w -e 'use List::Util qw(min); @a = (-10...5); print "@a\n",(min @a),"\n";' -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 0
doesn't produce an answer that ties with this
$ perl -w -e 'use List::Util qw(min); @a = (-10...-5); print "@a\n",min(@a);' -10 -9 -8 -7 -6 -5 -10
So why does 'min' in the first example return 0? Just Fixed the code I posted, buggy terminal I was copying from. Sorry.

Replies are listed 'Best First'.
Re: minimum expectation of min?
by dragonchild (Archbishop) on Jul 14, 2004 at 20:03 UTC
    I tried using Perl 5.8.0, List::Util 1.14 on RH 9 and it worked as expected.

    I did notice that the code you posted doesn't compile. Try the following:

    use strict; use warnings; use List::Util qw( min ); + print List::Util->VERSION, $/; + my @a = (-10...5); print "@a -> ",(min @a),"\n"; ---- 1.14 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 -> -10

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      Hmmn,your code gives me...
      1.09 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 -> 0
      looks like it is time to perl -MCPAN -e shell ....

      thanks

Re: minimum expectation of min?
by pbeckingham (Parson) on Jul 14, 2004 at 23:20 UTC

    I get 0 and -10 on Perl 5.8.0 List::Util 1.11, on OS X, but the correct -10, -10 on Perl 5.8.4, List::Util 1.13.

    Looks like it was fixed between 1.11 and 1.13.

Re: minimum expectation of min?
by dave_the_m (Monsignor) on Jul 14, 2004 at 20:06 UTC
    I get -10 in both cases. BTW, I presume there were some cut+paste errors in the above.

    Dave.