Leser: 26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
my @a=(1..100); my $i=0; my $end=@a; my $tauschA; my $tauschB; print "Gehordnet: $end \n"; foreach(@a){ ($a[$i],$a[$i+1]) = ($a[$i+1],$a[$i]); #print "@a \n"; $i++; print "Anzahl pro Zeile: $i \n"; last if($i==$end) } print "Ganzes Array: @a \n"; print $i;
1 2 3 4 5 6 7 8
my @leute = qw(donald daisy mickey minnie clyde bonnie); my @ungerade = grep $_ % 2 == 1, 0..$#leute; my @gerade = grep $_ % 2 == 0, 0..$#leute-1; @leute[@ungerade, @gerade] = @leute[@gerade, @ungerade]; print "Ladies first: @leute";
Guest User100Ich meine das Ergebnis ist:
2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
2 3 4 5 6 7 .... 99 100 1
1
2
3
4
5
1 2 3 4 5 6 7 .. 99 100
2 1 3 4 5 6 7 .. 99 100
2 3 1 4 5 6 7 .. 99 100
...
2 3 4 5 6 7 .. 99 100 1
2 3 4 5 6 7 .. 99 100 undef 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl -w use strict; use warnings; my @a=(1..100); print "Geordnet: @a \n"; for (my $i = 0; $i < (scalar @a)-1; $i += 2){ my $temp = $a[$i]; $a[$i] = $a[$i+1]; $a[$i+1] = $temp; } print "Ganzes Array: @a \n";