Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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
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
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 having an uproarious good time at the Monastery: (7)
As of 2015-09-01 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred temperature scale is:










    Results (4 votes), past polls