Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Calling method inside and outside of package

by lyklev (Pilgrim)
on Oct 28, 2010 at 19:50 UTC ( #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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://868133]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2018-07-22 03:25 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (451 votes). Check out past polls.