stephanm has asked for the wisdom of the Perl Monks concerning the following question:
my $var = "xxx\n"; my $var="zzz\n" unless defined($var); print $var;
#my $var = "xxx\n"; my $var="zzz\n" unless defined($var); print $var;
"my" variable $var masks earlier declaration in same scope at unlesste +st.pl line 2. Use of uninitialized value in print at unlesstest.pl line 3.
Even so this time the line is printed the warning about an undefined variable inside a defined() context does not make a lot of sense to me.Name "main::var" used only once: possible typo at unlesstest.pl line 2 +. zzz
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: conditional definition of variables
by FunkyMonk (Bishop) on Aug 23, 2008 at 13:52 UTC | |
by stephanm (Sexton) on Aug 23, 2008 at 14:21 UTC | |
|
Re: conditional definition of variables
by betterworld (Curate) on Aug 23, 2008 at 13:50 UTC | |
by stephanm (Sexton) on Aug 23, 2008 at 14:12 UTC | |
by JavaFan (Canon) on Aug 23, 2008 at 14:38 UTC | |
|
Re: conditional definition of variables
by shmem (Chancellor) on Aug 23, 2008 at 18:07 UTC | |
|
Re: conditional definition of variables
by rir (Vicar) on Aug 26, 2008 at 15:24 UTC | |
by JadeNB (Chaplain) on Aug 26, 2008 at 23:20 UTC |