Re: Strange interaction of "my"-variables with initialization

2008-01-14 Thread Dr.Ruud
Peter Daum schreef: > my $x = undef; > foreach ( qw(a b c) ) { > my $t = $x if $x; > warn( "\$t == ", $t||'undef', "\n" ); > $t = $_; > } > > $t would be initialized with the value of $x if that was true; > otherwise (at least that's what I would expect) $t should be > undefined, > so

Re: Strange interaction of "my"-variables with initialization

2008-01-13 Thread John W. Krahn
Chas. Owens wrote: On Jan 13, 2008 1:20 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: snip Statements don't define scope, braces and files define scope. snip so why should you be able to use it because it has been changed to this my $t = $x if $x; print "$t\n"; You can use it because it is i

Re: Strange interaction of "my"-variables with initialization

2008-01-13 Thread Chas. Owens
On Jan 13, 2008 1:20 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: snip > Statements don't define scope, braces and files define scope. snip > > so why should you be able to use it because it has been changed to this > > > > my $t = $x if $x; > > print "$t\n"; > > You can use it because it is in th

Re: Strange interaction of "my"-variables with initialization

2008-01-13 Thread John W. Krahn
Chas. Owens wrote: On Jan 13, 2008 6:22 AM, Peter Daum <[EMAIL PROTECTED]> wrote: snip my $t =$x if $x; snip $t would be initialized with the value of $x if that was true; otherwise (at least that's what I would expect) $t should be undefined, so the result would be as before. The real out

Re: Strange interaction of "my"-variables with initialization

2008-01-13 Thread Chas. Owens
On Jan 13, 2008 6:22 AM, Peter Daum <[EMAIL PROTECTED]> wrote: snip > my $t =$x if $x; snip > $t would be initialized with the value of $x if that was true; > otherwise (at least that's what I would expect) $t should be undefined, > so the result would be as before. The real outcome, however, i

Re: Strange interaction of "my"-variables with initialization

2008-01-13 Thread John W. Krahn
Peter Daum wrote: Hi, Hello, I just got bitten by a very simple issue, where Perl behaves totally different from what I had expected; According to the documentation, lexical variables are visible only after the line they have been declared in; they may be initialized; otherwise their value i