[Edinburgh-pm] code style question

Robert Rothenberg robrwo at gmail.com
Tue Aug 16 09:55:57 PDT 2011


On 16/08/11 12:49 Miles Gould wrote:
> On Tue, Aug 16, 2011 at 11:46 AM, Alex Brelsfoard
> <alex.brelsfoard at gmail.com> wrote:
>> if ($::var) {
>>    ...
>> }
> 
> I have never seen this before. Isn't it just referencing a variable in
> the package whose name is empty?
> 
>> To my understanding this is a bit messy, and not to mention potentially
>> dangerous as it kinda goes against the "use strict;" methodology, does it
>> not?
> 
> perl -E 'use strict; $::fred = 7; say $::fred'
> 
> works fine for me! So I guess the point of this scheme is that it
> allows you to use global variables (worse, *undeclared* global
> variables) under the strict pragma. ...

My guess is that the script was written for Perl 4, when that was how one
referred to global variables.

Rather than rolling your own import function (Exporter was not included with
Perl 4), one often wrote modules with things like

  sub main::foobar {

   ...

  }



More information about the Edinburgh-pm mailing list