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