Octavian Rasnita wrote:
> 
> I've tried the following script and it works fine:
> 
> use strict;
> my $text = 1;
> my $text = 2;
> print $text;
> 
> Shouldn't perl disallow defining the $text variable a second time in the same
> script if using "use strict"?

Lexical variables are intended for temporary use in a limited scope. Using them
properly alleviates the burden of finding multiple names for variables with an
identical purpose in different scopes.

Declaring a variable with the same name in the same scope is valid semantically
(it discards the previous variable and provides a new one) but is usually a
mistake, and compiling the program with warnings enabled will generate the 
message

  "my" variable $var masks earlier declaration in same scope

You should always enable lexical warnings as well as strictures.

HTH,

Rob


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to