I'm curious why this dumps the reference to @result.

Consider:

22:45 >perl -MData::Dumper -wE "my @c = ( 5, 7, 11 ); say Dumper @c; s +ay Dumper \@c;" $VAR1 = 5; $VAR2 = 7; $VAR3 = 11; $VAR1 = [ 5, 7, 11 ]; 22:46 >

I prefer the second form, because I can more easily see the related things grouped together (but YMMV).

my run at the problem resulted in this code:

And now the problem can be diagnosed! It’s in this line:

my @factors = [ ];

The square brackets create an empty, anonymous array, and a reference to this anonymous array becomes the first element in the named array @factors. Later, when List::Util::max is called on @factors, it tries to compare the elements in the array to one another, but fails because it doesn’t know how to compare an array reference (that first element) to a Math::BigInt object.

The solution is to simply remove the anonymous array reference, which isn’t needed anyway:

my @factors;

and the code now runs without error!

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^3: List::Util can't find max in array of BigInts by Athanasius
in thread List::Utils can't find max in array of BigInts by mgatto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.