Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Use reference for functions in functions

by 7stud (Deacon)
on Feb 25, 2013 at 19:39 UTC ( #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


Comment on Re: Use reference for functions in functions
Download Code
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
Node Status?
node history
Node Type: note [id://1020556]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-07-12 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (240 votes), past polls