Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Use reference for functions in functions

by 7stud (Deacon)
on Feb 25, 2013 at 19:39 UTC ( [id://1020556]=note: print w/replies, xml ) Need Help??


in reply to Use reference for functions in functions

use strict; use warnings; use 5.012; package Dog; sub new { my $class = shift; my $self = {}; bless $self, $class; } sub bark { say 'woof'; } sub do_math { say '2 + 2 = 4'; } package main; sub func1 { my $obj = shift; $obj->do_math(); } sub func2 { my $obj = shift; $obj->bark(); func1($obj); } my $dog = Dog->new(); func2($dog); --output:-- woof 2 + 2 = 4

Replies are listed 'Best First'.
Re^2: Use reference for functions in functions
by T_I (Novice) on Feb 26, 2013 at 06:59 UTC
    Thanks,

    It's been years since I've did something with objects in Perl. (first and last time was in 2009) I forgot objects are already references. I'll test this at work and post the findings.

    Edit: Just tested the removal of \ in the prototyping and it works flawlessly. Thanks for the reminder that objects are already references..

      Do you know about Moose? Moose is the new OO paradigm in perl. See here and chromatic's Modern Perl book here.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-29 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found