Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 chanting in the Monastery: (8)
As of 2015-07-03 06:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (48 votes), past polls