in reply to Re: Scope, package, and 'my' variables
in thread Scope, package, and 'my' variables
#!/usr/bin/perl -w use strict; my $x = 1; BEGIN { $x = 2; } print $x, "\n"; # 1 BEGIN { my $x = 1; } print $x, "\n"; # (sic: ) undefined, failure under strict.pm # Apr 30, 05: Actually, mine doesn't fail and prints '1' my $x = 1; # 'my' generates a 'masks declaration' warning { package foo; $x = 2; } print $x, "\n"; # 2 my $x = 1; # 'my' generates a 'masks declaration' warning { package foo; my $x = 2; } print $x, "\n"; # 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Scope, package, and 'my' variables
by revdiablo (Prior) on Apr 30, 2005 at 17:56 UTC |