in reply to Stupid question
Nearly every Perl script I write follows this format:
So you can prevent your subroutine from accessing your "main" variables by putting them where I wrote $putMainVarsHere.#!/usr/bin/perl -w use strict; use Other::Modules qw< ImportedFunction >; use vars qw< $Globals >; Main( @ARGV ); exit; sub Routine { ... } BEGIN { my $static= "Initial value"; sub usesStatic { ... } } sub Main { my $putMainVarsHere; ... } __END__
This style has evolved for quite a while and there are specific reasons for almost every aspect of it. I find it catches quite a few errors for me.
I was going to explain my reasons for most aspects of this style, but I decided that that would be more appropriate elsewhere.
(updated twice)
Update: Here are some justifications for some of my decisions that I collected quite a while ago planning to write this up more formally. Instead I've just moved them from my scratchpad to here:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Stupid question
by runrig (Abbot) on May 19, 2011 at 16:29 UTC | |
by tye (Sage) on May 19, 2011 at 16:47 UTC | |
by runrig (Abbot) on Apr 14, 2012 at 06:05 UTC | |
by tye (Sage) on Apr 14, 2012 at 15:46 UTC | |
by runrig (Abbot) on May 11, 2012 at 23:52 UTC | |
Re^2: Stupid question
by flexvault (Monsignor) on May 12, 2012 at 10:32 UTC | |
by tye (Sage) on May 12, 2012 at 17:34 UTC | |
by flexvault (Monsignor) on May 13, 2012 at 08:16 UTC | |
by tye (Sage) on May 13, 2012 at 22:22 UTC | |
by flexvault (Monsignor) on May 14, 2012 at 08:27 UTC | |
by aaron_baugher (Curate) on May 12, 2012 at 11:50 UTC |