Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Calling method inside and outside of package

by lyklev (Pilgrim)
on Oct 28, 2010 at 19:50 UTC ( [id://868133]=note: print w/replies, xml ) Need Help??


in reply to Calling method inside and outside of package

Your example works, because your routine xxx does nothing special. If you have a routine inside a package however, you will either want to do something with the data contained in your object, or you have a generic function that does not access your object's data.

In the first case you would call the function as kcott mentioned, so as

$obj -> xxx("hi");
If you call the function from inside the package, you cannot access the data contained in the object, because you are passing an empty string instead of an object to the function.

If you have a simple function (say, for adding two numbers), you can write a function like you normally would, so without getting the class name from the arguments.

And never call a routine or program test --- there is probably another function or program with that name, which will take you a few hours to find out.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://868133]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-19 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found