1 2 3 4
@aa = ("Phe","Val","Asn","Gln","His","Leu","Cys","Gly","Ser"); foreach $i (@aa) { print $i; };
1 2 3
foreach $i ("Phe--","Val--","Asn--","Gln--","His--","Leu--","Cys--","Gly--","Ser"){ print $i; };
1 2 3 4
my @aa = ("Phe","Val","Asn","Gln","His","Leu","Cys","Gly","Ser"); foreach my $i (@aa) { print "$i--"; };
1 2 3 4 5 6 7
my @aa = ("Phe","Val","Asn","Gln","His","Leu","Cys","Gly","Ser"); my $ende = pop @aa; # entnimmt das letzte Element und speichert es zwischen foreach my $i (@aa) { print "$i--"; }; push @aa, $ende; # setzt das letzte Element wieder an seinen Platz print "$ende\n";
2015-03-18T18:38:17 der_thomasLösung mit pop und push
1 2 3 4 5 6 7
my @aa = ("Phe","Val","Asn","Gln","His","Leu","Cys","Gly","Ser"); my $isFirst = 1; for my $i (@aa) { if ($isFirst) { $isFirst = 0; } else { print "--"; } print $i; };
1 2
@aa = ("Phe","Val","Asn","Gln","His","Leu","Cys","Gly","Ser"); print join "--", @aa;
1 2 3 4 5 6 7 8
my @aa = ("Phe","Val","Asn","Gln","His","Leu","Cys","Gly","Ser"); my $s = ""; foreach my $i (@aa) { $s .= "--" if $s; $s .= $i; } print $s;
1
2
3
4
5
6
7
my @Werte = ( "Phe" , "Val" , "Asn" , "Gln" , "His" , "Leu" , "Cys" , "Gly" , "Ser" );
my $Trenner = "--";
foreach my $i ( @Werte )
{
print $Trenner . $i;
};