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

Re: defining variables using my - subroutines

by Arunbear (Parson)
on Sep 05, 2012 at 15:59 UTC ( #991884=note: print w/ replies, xml ) Need Help??

in reply to defining variables using my - subroutines

Declare them nearest to the point where they are used (usually):

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub make_them { my $var = 1; my @array = qw(a b c); return ($var, \@array); } sub use_them { my ($var, $array_ref) = @_; print Dumper($var, $array_ref) . "\n"; } while ( 1 ) { my ($var, $array_ref) = make_them(); use_them($var, $array_ref); last; # demo }

Comment on Re: defining variables using my - subroutines
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2015-11-28 14:18 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (742 votes), past polls