Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

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

    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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2016-10-22 00:05 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (291 votes). Check out past polls.