Wednesday, 15 February 2012

uninitialized value error in perl -



uninitialized value error in perl -

i'm pretty new perl (and programming in general i'm used python).

use strict; utilize warnings; utilize diagnostics; $simple_variable = "string"; print $simple_variable;

basically want know why script returns uninitialized value error, since variable defined.

thanks

my creates variable , initializes undef (scalars) or empty (arrays , hashes). returns variable creates.

as such,

print $simple_variable;

is same thing as

my $simple_variable = undef; print $simple_variable;

you meant do

my $simple_variable = "string"; print $simple_variable;

i'm not sure why asking because perl told much. programme outputs following:

"my" variable $simple_variable masks before declaration in same scope @ a.pl line 6 (#1) (w misc) "my", "our" or "state" variable has been redeclared in current scope or statement, eliminating access previous instance. typographical error. note before variable still exist until end of scope or until closure referents destroyed.

note how new declaration has effect of "effectively eliminating access previous instance".

perl

No comments:

Post a Comment