Hello! I'm quite new to Perl 5, and often struggle with the concept of references (as other languages I've dabbled in do not use these)

I'm going through a Ruby OOP book that I like and am trying to use the experimental 'class' features to familiarize myself with the language more (I'm learning it to work on a project with a friend)

In the following snippet, the code for the ratio method was working fine. However, with the addition of the gear_inches method, I get a cryptic (to me) error: Can't use string ("26") as a symbol ref while "strict refs" in use at gear1.pm line 15.

This seems to imply that when I create the new class instance at the end, the rim parameter value of 26 is interpreted as a symbolic reference when the 'gear_inches' function is called. Upon reading up on symbolic references: https://perldoc.perl.org/perlref#Symbolic-references

It seems that Perl is saying that '26' (the value of the scalar) is taken to be the name of a variable. I have no idea how this could possibly be given the simplicity of the code. Every problem that produced an error message I couldn't make sense of previously involved de referencing, a concept with which I've not previously dealt. I guess this is probably also that somehow (lol?) Thank you for your time!
use v5.40.0; use experimental 'class'; class Gear { field $chainring :param :reader; field $cog :param :reader; field $rim :param :reader; field $tire :param :reader; method ratio { return $chainring/$cog; } method gear_inches { return ratio * $rim + ($tire * 2); } } say Gear->new(chainring=>52, cog=>11, rim=>26, tire=>1.5)->gear_inches +;

In reply to 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.