The basic problem here : my variables are not global, they don't belong to any package. Your call to two returns the current value of $image, which (on your call to one is set to "param"). In other words $image that you declared with my is still in scope in two. If you wanted two to have its own $image, you'd have to use my in the subroutine. That's why you're seeing that behavior. (out of curiosity, and it might help conceptually, could you tell us what were you expecting to see, BTW?)

Packages are not instances; you can think of them as "last names" (i.e. things that help you distinguish this 'Bob' from that 'Bob'). You might be confusing packages with objects; an object is a reference to a Perl data stucture (even a subroutine!) that's been blessed *into* a package. (If you're trying to do some OOP in Perl, you can start with various monks' tutorials in the Tutorials section on this site, or with perldoc perltoot on your own system)

Also, to access the variables defined in Pack, you don't use it, you just say $Pack::image (e.g. ... and note here that won't work because there is no such variable defined, because the $image you've created isn't in the Pack package!)

I have a (partial) scoping tutorial here that might help clear this up. IF you read that, though, I'd (a) pay attention to the comments that follow and (b) follow the "Coping with Scoping" link because that's more accurate.

HTH

Philosophy can be made out of anything. Or less -- Jerry A. Fodor


In reply to Re: Instance Module by arturo
in thread Instance Module 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, 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.