Software Sue

Link to Simply Sue
Link to Sustainability Sue
location: software/scripting/perl control constructs Skip navigation : Home  

Perl Control Constructs


In Perl, these include loops and branches, but no multi-branch.

Curly brackets should be used around control construct statement blocks, even when there is only one statement.

Loops

# Example of looping in Perl with a while loop

$input = ;
while $input ne "" {
print ($input);
}

# Example of looping in Perl with a for loop

for ($i = 0; $i < @myarray ; $i++) {
print ($myarray[$i]\n");
}

Branches

# Example of branching in Perl with an if-else statement

if ($myvariable eq "mine all mine") {
print "You're not having it!";
}
else {
print "OK, it's yours!";
}