let's see if i can shed some light on this.
your statement:
print("Defined: <<$z>>\n") if defined(my $z="x");
this will be evaluated like this if i'm not mistaken:
( print("Defined: <<$z>>\n") ) && defined(my $z="x");
or a simplistic version:
(print $z) && (my $z = 'bar');
try and 'use strict' and you'll see where the problem lies.
what's happening is that the parser is a bit unhappy.
first you use a variable, then you declare it. see, the parser works left to
right,
so it will see your $z before you declare it and tell you so under use
strict.
runtime things work right to left, so that's why
$z = 'bar; (print $z) if $z;
works just fine.
hth,
Jos Boumans
> Hi!
>
> Isn't this weird?
>
> #!/usr/bin/perl -w
> print("Defined: <<$z>>\n") if defined(my $z="x");
> print "Assigned: <<$z>>\n";
>
> Produces:
>
> Defined: <<>>
> Assigned: <<x>>
>
> So it looks like $z *is* defined but *not* assigned until we are out of
> the 'if' statement. Is it a bug? My understanding it should either stay
> undefined or defined *and* assigned at the same moment, am I missing
> something?
>
> There's nothing helpful in the documentation, the only short note in
> perlvar admits that whatever more or less detailed description of my()
> scope issues it has for complex statements -- does *not* apply to simple
> ones (like the above example). However, description of the scoping
> within simple statements is nowhere to be found :(.
>
> -w switch produces complaints about '"main::z" used only once' but this
> is not very helpful, I'd like to know *why* it appears to not being
> properly initialized...
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]