bcarroll has asked for the wisdom of the Perl Monks concerning the following question:
use warnings; use strict; my ($str1, $str2, $str3); my @arr = ('1', '2', '3'); ... do stuff with the variables ...
Does perl have any magical tricks to put the variable declaration/initialization in a subroutine or some other mechanism so that is not the top chunk of the script?
something like this (which does not work)
use warnings; use strict; initializeVars(); ... do stuff with the variables ... sub initializeVars{ our ($str1, $str2, $str3); our @arr = ('1', '2', '3'); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: declare/initialize variables at bottom of script?
by BrowserUk (Patriarch) on Jun 11, 2013 at 18:18 UTC | |
|
Re: declare/initialize variables at bottom of script?
by AnomalousMonk (Archbishop) on Jun 11, 2013 at 22:13 UTC | |
|
Re: declare/initialize variables at bottom of script?
by 5mi11er (Deacon) on Jun 11, 2013 at 18:06 UTC | |
by bcarroll (Pilgrim) on Jun 11, 2013 at 18:17 UTC | |
|
Re: declare/initialize variables at bottom of script?
by Laurent_R (Canon) on Jun 11, 2013 at 22:11 UTC | |
|
Re: declare/initialize variables at bottom of script?
by Preceptor (Deacon) on Jun 11, 2013 at 18:20 UTC | |
|
Re: declare/initialize variables at bottom of script?
by dcmertens (Scribe) on Jun 11, 2013 at 21:31 UTC |