The Documentation for the reduce function in List::Util suggests that the use of $a and $b in the block on line 39 is correct (and aparently intended to be "similar" to the way sort uses $a and $b) and totally unrelated to the use of $a on line#49.

I would suspect the core of your problem is that you aren't importing "reduce" when you use List::Util qw( max min ); (since the docs for List::Util suggest that it doesn't export anything by default) but fixing that doesn't seem to have any affect.

My best guess is that List::Util doesn't play nicely with blessed obejcts ... but that seems unlikely.

...oh, wait a minute. your abs() method isn't returning an object, it's returning a number. ... The first pass reduce makes will be on the first two obejcts in your list, which you've told it to call the abs() method on each, and sum the result. In the second pass $a will be the result of the first pass, and $b will be the next obect in your list ... maybe it's at that point that you get the error about not being able to call abs (because $a is just a simple scalar) ... but i would expect a slightly differnet error about it being unblessed, not about it being undefined ... hmmmmm.


In reply to Re: Can't call method "abs" on an undefined value. by hossman
in thread Can't call method "abs" on an undefined value. by HollyKing

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.