CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced: goto - effect on the scope of variables: Edit Log



aravindprasad
Novice

Jul 8, 2009, 1:08 PM


Views: 1343
goto - effect on the scope of variables

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.


Code
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)


Edit Log:
Post edited by aravindprasad (Novice) on Jul 8, 2009, 1:12 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives