Download presentation
Presentation is loading. Please wait.
Published byAlexis Hancock Modified over 9 years ago
2
BLOCK is enclosed by curly brackets {}. Keep in mind that blocks are always bounded by curly brackets, even if your block has only one code line. Every block statement is evaluated by Perl as an individual statement.
3
The syntax format for a Perl BLOCK { statement;... statement; statement; }
4
We use blocks: with the conditional statements like if and unless with the loop statements like while, for, foreach, until by itself, and in this case we call them bare or naked blocks
5
Bare Block can be labeled or not and it can be assimilated with a loop that is executed only once and therefore you can use within it the loop controls: next, last, redo.
6
can be used with one of the following syntax forms: LABEL BLOCK LABEL BLOCK continue BLOCK
7
Anonymous Block Is an unlabelled bare block. { my $var1 = 2+4; my $pi = 3.14; my $var = $var1 + $pi; } Example:
8
You can name a block by giving it a label that represents an identifier for it. The label: precedes the block begins with a letter or an underscore (_) and can contain either underscores or alphanumerical characters ends with the colon character (:) NOTE: As a rule of thumb, I suggest you to use for labels only uppercase characters, so as not to conflict with reserved words - because Perl language is case sensitivity.
9
Example of a Labeled Bare Block: @numbers = (1, 2, 3, 4, 5); $count = 5; MYLABEL: { next if $count-- == 0; $count1 = $count; # increment each element of the array $_++ foreach @numbers; redo; }continue { print "\@numbers = (@numbers)\n"; } print "that's all\n";
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.