Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2014-07-25 14:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (172 votes), past polls