next up previous
Next: 3. Regular expressions Up: 6. What Perl looks Previous: 1. Data types

2. Control constructs

Perl's control constructs will look very familiar to experienced programmers:

if (condition) {
	BLOCK
} else {
	BLOCK
}

while (condition) {
	BLOCK
}

until (condition) {
	BLOCK
}

for ($i=0; $i <= $max; $i++) {
	BLOCK
}

foreach $element (@list) {
	print $element;
}

Some shortcuts will not be familiar, but will delight people who are sick of typing curly brackets:

print "X is true" if $x;
print "X is false" unless $x;

open (FILE, "file.txt") || die ("Can't open file.txt: $!");



Kirrily Robert
1999-04-06