Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 avoiding work at the Monastery: (4)
As of 2014-10-02 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (41 votes), past polls