in reply to my and local variable significance in a particular case
Suppose I have perl script which has no 'use strict'/'use warnings' in it. In that case what is the significance of a 'my' and 'local' variable in it.You seem to be under the impression that "strict" and "my" are related. They are not, although if you read Perlmonks you may get the impression they are.
my creates a lexical variable. It's the only way to create a lexical variable, and the variable is always lexical. Whether or not strict or warnings are enabled.
local creates a temporary new value for a package variable (technically, the implementation is slightly different, but for most practical purposes, you won't notice) -- the old value is restored when leaving the current, lexical, scope. However, this temporary value is visible from everywhere, even if you call something in a different scope. The old, stashed away, value isn't accessable from Perlland.
And again, whether or not strict or warnings are enabled is utterly irrelevant.
As for your program, add the following, and see the difference:
print $::a, "\n"; # prints the empty string print $::b, "\n"; # prints 4
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: my and local variable significance in a particular case
by Anonymous Monk on Apr 25, 2012 at 03:51 UTC | |
by JavaFan (Canon) on Apr 25, 2012 at 06:22 UTC |