Commit | Line | Data |
8d063cd8 |
1 | #!./perl |
2 | |
79072805 |
3 | # $RCSfile: goto.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:56 $ |
8d063cd8 |
4 | |
79072805 |
5 | print "1..5\n"; |
8d063cd8 |
6 | |
79072805 |
7 | while ($?) { |
8d063cd8 |
8 | $foo = 1; |
9 | label1: |
10 | $foo = 2; |
11 | goto label2; |
12 | } continue { |
13 | $foo = 0; |
14 | goto label4; |
15 | label3: |
16 | $foo = 4; |
17 | goto label4; |
18 | } |
19 | goto label1; |
20 | |
21 | $foo = 3; |
22 | |
23 | label2: |
24 | print "#1\t:$foo: == 2\n"; |
25 | if ($foo == 2) {print "ok 1\n";} else {print "not ok 1\n";} |
26 | goto label3; |
27 | |
28 | label4: |
29 | print "#2\t:$foo: == 4\n"; |
30 | if ($foo == 4) {print "ok 2\n";} else {print "not ok 2\n";} |
31 | |
32 | $x = `./perl -e 'goto foo;' 2>&1`; |
8d063cd8 |
33 | if ($x =~ /label/) {print "ok 3\n";} else {print "not ok 3\n";} |
79072805 |
34 | |
35 | sub foo { |
36 | goto bar; |
37 | print "not ok 4\n"; |
38 | return; |
39 | bar: |
40 | print "ok 4\n"; |
41 | } |
42 | |
43 | &foo; |
44 | |
45 | sub bar { |
46 | $x = 'exitcode'; |
47 | eval "goto $x"; # Do not take this as exemplary code!!! |
48 | } |
49 | |
50 | &bar; |
51 | exit; |
52 | exitcode: |
53 | print "ok 5\n"; |