Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Anonymous Monk 2 above is right in the general sense that you probably want to familiarize yourself with a Perl object framework like Moose, but that is not the answer to your question. Likewise, strict would help but does not answer your question (see Use strict warnings and diagnostics or die).

When you call Dog::play ($name); you are not passing the idea of a variable called $name to Dog::play, but the contents the the variable in current scope. You call Dog::play ($name); in the Cat package, and it has variable called $name. So Perl inserts Garfield into the argument list.

Of course, this is further confused by your use of our and lack of scope declaration for $name = "Garfield";. If instead you write our $name = "Garfield";, you can now get the two different results by calling

Dog::play ($Dog::name); # Prints Odie catches a tennis ball.
or
Dog::play ($name); # Prints Garfield catches a tennis ball.

The comments about better methodology would have helped catch and clarify these issues a number of different ways.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


In reply to Re: Package problems by kennethk
in thread Package problems by Anonymous Monk

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (5)
    As of 2020-07-07 09:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?