perl coding style question

Randy J. Ray rjray at blackperl.com
Tue Aug 16 18:32:05 BST 2011


Alex Brelsfoard wrote:
> Hi All,
> 
> I just came across some code that used some old-style coding practice, and I
> wanted to know if there was still any GOOD reason for using it.
> 
> The code I saw was referencing variables using the $:: pragma:
> 
> if ($::var) {
>    ...
> }
> 
> 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?

This isn't a "pragma", this is a short-hand way of referring to the "main" 
namespace. "$::var" is the same as "$main::var", and is sometimes necessary 
when you need to refer to a value in "main" from within a module. Generally, 
having to refer to a different namespace at all breaks encapsulation, so it 
should only be done if absolutely necessary.

Randy
-- 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Randy J. Ray      Sunnyvale, CA      http://www.rjray.org   rjray at blackperl.com

Silicon Valley Scale Modelers: http://www.svsm.org


More information about the london.pm mailing list