in reply to if else condition not assigning value when using my

Each code block creates a new scope.
#!/usr/bin/perl -- use strict; use warnings; { my $one = 1; my $two = 1; { my $one = 3; ## new $one my $two = 4; ## new $two print "$one $two\n"; # old $one $two } if( time ){ my $one = 5; ## new $one my $two = 6; ## new $two print "$one $two\n"; # old $one $two } print "$one $two\n"; # old $one $two } ### NO $one/$two exist here ## print "$one $two\n"; __END__ 3 4 5 6 1 1
See Coping with Scoping

Replies are listed 'Best First'.
Re^2: if else condition not assigning value when using my
by Anonymous Monk on Apr 08, 2010 at 23:19 UTC
    Sorry, the first two comments "# old $one $two" are a copy/paste typo.