A method in Perl always needs to be told on which object instance it should operate. Your call to ratio is missing that, it should be $self->ratio - and that's it. $self is a variable which is automatically available in a method and it holds the "current" object, which is what you want.

The error message is indeed cryptic for the modern Perl style you are using. It comes from the way Perl passes arguments to its subroutines (and methods): The object on which a method operates is simply passed as its first parameter. So, if you call ratio without the invocant, then the method will interpret the first parameter 26 as the object. The message would be clearer written as say Can't use string ("26") as an object. The current text and its reference to "strict refs" comes from an old feature of Perl which should not be used at all in new code... so maybe we could convince the Perl devs to change that text.

Edit: The code had a typo (self->ratio should read $self->ratio).

In reply to Re: Using perlclass 'methods' by haj
in thread Using perlclass 'methods' by drudgesentinel

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.