in reply to Package problems
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
orDog::play ($Dog::name); # Prints Odie catches a tennis ball.
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.
|
---|