Flow control
http://perldoc.perl.org/perlsyn.html#Compound-Statements
http://perldoc.perl.org/perlintro.html#Conditional-and-looping-constructs
Conditionals
my $false_1 = 0;
my $false_2 = '0';
my $false_3 = '';
my $false_4 = ();
my $false_5 = undef;
my $true = 'rest';
if ($false_1) {
say 'if block executed';
} elsif ($true) {
say 'elsif block executed';
} else {
say 'else block executed';
}
Loops
- for / foreach : http://perldoc.perl.org/perlsyn.html#Foreach-Loops
- next, do, last, continue : http://perldoc.perl.org/perlsyn.html#Loop-Control
- next: go the next loop iteration
- last: exit the loop
- redo: restart the loop
while
my @list = ('one', 'two', 'three');
while (@list) {
say shift @list;
}
Read more: http://perldoc.perl.org/perlsyn.html#Loop-Control
until
for
This is the Perl way for for-loops:
for (1..10) {
say 'Counter: ' . $_;
}
However, C-style loops could be used as well:
for (my $i = 0; $i < 10; $i++) {
say 'Counter: ' . ($i + 1);
}
Read more: http://perldoc.perl.org/perlsyn.html#For-Loops
foreach
For and foreach can be used as synonyms.
Labels and continue
while
, until
and for
loops support labels in order to