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
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |