X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlsyn.pod;h=9d0c9209eaa8d220486b666a7a84e3b9226c282f;hb=bbd5c0f5ad81733b079008f34cd05cd9aef7d917;hp=6d820b6882e8e9f30a0bf3833aed65789b9ed40a;hpb=4b19af017623bfa3bb72bb164598a517f586e0d3;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod index 6d820b6..9d0c920 100644 --- a/pod/perlsyn.pod +++ b/pod/perlsyn.pod @@ -263,7 +263,7 @@ available. Replace any occurrence of C by C. =head2 For Loops -Perl's C-style C loop works exactly like the corresponding C loop; +Perl's C-style C loop works like the corresponding C loop; that means that this: for ($i = 1; $i < 10; $i++) { @@ -279,8 +279,10 @@ is the same as this: $i++; } -(There is one minor difference: The first form implies a lexical scope -for variables declared with C in the initialization expression.) +There is one minor difference: if variables are declared with C +in the initialization section of the C, the lexical scope of +those variables is exactly the C loop (the body of the loop +and the control sections). Besides the normal array index looping, C can lend itself to many other interesting applications. Here's one that avoids the @@ -309,9 +311,12 @@ The C keyword is actually a synonym for the C keyword, so you can use C for readability or C for brevity. (Or because the Bourne shell is more familiar to you than I, so writing C comes more naturally.) If VAR is omitted, C<$_> is set to each value. -If any element of LIST is an lvalue, you can modify it by modifying VAR -inside the loop. That's because the C loop index variable is -an implicit alias for each item in the list that you're looping over. + +If any element of LIST is an lvalue, you can modify it by modifying +VAR inside the loop. Conversely, if any element of LIST is NOT an +lvalue, any attempt to modify that element will fail. In other words, +the C loop index variable is an implicit alias for each item +in the list that you're looping over. If any part of LIST is an array, C will get very confused if you add or remove elements within the loop body, for example with @@ -388,8 +393,18 @@ structures. } There is no official C statement in Perl, because there are -already several ways to write the equivalent. In addition to the -above, you could write +already several ways to write the equivalent. + +However, starting from Perl 5.8 to get switch and case one can use +the Switch extension and say: + + use Switch; + +after which one has switch and case. It is not as fast as it could be +because it's not really part of the language (it's done using source +filters) but it is available, and it's very flexible. + +In addition to the above BLOCK construct, you could write SWITCH: { $abc = 1, last SWITCH if /^abc/;