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 | |
by 7stud (Deacon) on Feb 27, 2013 at 06:48 UTC |