Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Getting Confused with the '->' operatorby elusion (Curate) |
on Sep 30, 2002 at 22:34 UTC ( [id://201878]=note: print w/replies, xml ) | Need Help?? |
The arrow operator always operates on the value to its left. That means that your second example would be equivalent to this:
where the result variables are temporary. In order for the code to work as expected, the methods (name, job, wife, fav_food) must return the original object. A sample method that works this way would look like this (assuming the object is a hash ref): This code fragment will set the value and return the object if a value is given, else it will return what the name is set as. So why do you sometimes see the original object ($Person in this case) have multiple method calls originating from the original obect on multiple lines? Because if the method returns a value other than itself (which is quite common), it will try to call the method on that value, and most likely fail. elusion : http://matt.diephouse.com
In Section
Seekers of Perl Wisdom
|
|