my $a = $a;#refrences whatever was the scoped $a before
in the following paragraph I said global var, meant lexical. my bad =/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
From: sfritz [EMAIL PROTECTED]
having two
my $name = Sean Fritz;
my $name = Sean W. Fritz; #functions as the shown assignment
statment,
just functions as an assignment statment (I believe) and dosen't
alocate any memory or destroy the previous variable. I could be
Friends,
When we use strict pragma, is there a way to prevent redefining a
variable?
use strict;
my ($i) = 5;# $i defined
print (Val of i = $i);
my ($i) = 6;# $i redefined?Could this be tagged as an
error?
print (Val of i = $i);
Thanks,
Rex
You could use a constant instead.
-- code --
use strict;
use constant INDEX = 5; # I'm assuming $i refers to an index. Use more
descriptive variable names...
print (Value of index . INDEX . \n);
INDEX = 6;
-- end code --
Run that and you will get the following error.
Can't modify constant
John,
Thanks for your input. However, what I was expecting was to have variables
that are scoped properly without being accidentally redefined within the
same scope. Using constants would prevent the redefining problem,
nonetheless they would not allow me to alter the values either!
In
if you also run under -w or do a 'use warnings' it will give you a warning if
you're doing something like that.
consider this:
use strict;
use warnings;
my $i = 'foo';
my $i = 'bar';
will print to stderr with:
my variable $i masks earlier declaration in same scope at C:\tmp\t.pl line 6.
There is no way to re-define the variable in perl. The $, @, and % all
have thier own seperate namespaces, and thus the definition
my $in;
my @in;#creates *both* a scalar and array
the best way is to
use warnings;#start of every program!
and it will give you a bit of ugly output to