Perl.ControlStructures History
Hide minor edits - Show changes to markup
July 13, 2005, at 11:55 PM
by �zg�n
Added lines 1-84:
(:source lang=perl:)
#!/usr/bin/perl
#
# Kontrol yapıları
#
use strict;
use warnings;
my (@d1, @d2, @d3, @d4);
my ($x1, $x2, $x3, $x4);
# foreach: 1
print "1. foreach: ";
@d1 = (1 .. 10);
foreach $x1 (@d1) {
print "$x1 - ";
}
print "\n";
# foreach: 2
print "2. foreach: ";
@d1 = (11 .. 20);
foreach (@d1) {
print "$_ - ";
}
print "\n";
# foreach: 3
print "3. foreach: ";
foreach (2 .. 8) {
print "$_ - ";
}
print "\n";
# foreach: 4
print "4. foreach: ";
foreach my $letter ('A' .. 'Z') {
print "$letter - ";
}
print "\n";
# foreach: 5 (for gibi davranan foreach)
print "5. foreach: ";
foreach (my $number = 0; $number < 4; $number++) {
print "$number - ";
}
print "\n";
# foreach: 6
print "6. foreach: ";
foreach my $kedi ('Siyam', 'Tekir', 'Van') {
print "$kedi - ";
}
print "\n";
# foreach: 7
print "7. foreach: ";
foreach ('Siyam', 'Tekir', 'Van') {
print ;
}
print "\n";
# redo: D�ng� şartını �nemsemeden d�ng�de d�ner.
print "redo: ";
my $number = 1;
while ($number <= 5) {
if ( $number <= 10 ) {
$number++;
redo
}
}
print "$number \n";
# last ile d�ng�n�n sonlandırılması.
print "last ile d�ng�n�n sonlandırılması: ";
foreach (1 .. 5) {
print "$_ -";
last if ($_ == 3);
}
print "\n";