
aravindprasad
Novice
Jul 8, 2009, 1:08 PM
Post #1 of 2
(909 views)
|
|
goto - effect on the scope of variables
|
Can't Post
|
|
Hi all, I am in this situation where using goto-LABEL seems to be the best way to go forward. But I am completely lost on the scope of the variables in this method. Please look at the script below. Assume strict mode.
01 @array = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 02 for (my $var=0; $var<@array; $var++) { 03 # blah blah blah 04 if ($array[$var] == 2) { 05 goto PRINT; 06 INLOOP: 07 print "$array[$var]\n"; 08 } else { 09 print "$array[$var]\n"; 10 } 11 } 12 PRINT: 13 print "I got to PRINT\n"; 14 unless ($var > @array) { 15 goto INLOOP; 16 } 17 print "I have reached the end. Exitting...\n"; I would like to know whether $var is valid in the "unless" statement in line 14 since it lies out side the for loop. Also I am curious whether goto can be used to jump between subroutines. Would the answers change if I were not in the strict mode? Thanks and regards, -Aravind
(This post was edited by aravindprasad on Jul 8, 2009, 1:12 PM)
|