Thread my richtig setzen (18 answers)
Opened by Byonik at 2010-06-24 10:28

hlubenow
 2010-06-24 21:10
#138916 #138916
User since
2009-02-22
875 Artikel
BenutzerIn
[default_avatar]
Hallo,

my-Variablen gelten innerhalb eines Blocks, das heißt, eines Bereichs, der im Perl-Skript in {} gefaßt ist. Ist die my-Deklaration außerhalb eines expliziten {}-Bereichs, gilt sie für das ganze Skript.

In "codon2aa()" führt die Zeile
Code (perl): (dl )
my $codon = @_;

dazu, daß $codon die Anzahl der Element von @_ zugewiesen wird.
Wahrscheinlich muß es
Code (perl): (dl )
my $codon = shift(@_);

oder (wie man es üblicherweise verkürzt):
Code (perl): (dl )
my $codon = shift;

heißen. Ich würde "codon2aa()" so schreiben (wenn ich das richtig verstanden habe):
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl

use warnings;
use strict;

sub codon2aa {
    my $codon = shift;
    my %aa = ("TCC" => "S", "TCG" => "S", "TCT" => "S", "TTC" => "F",
              "TTT" => "F", "TTA" => "L", "TTG" => "L", "TAC" => "Y",
              "TAT" => "Y", "TAA" => "_", "TAG" => "_", "TGC" => "C",
              "TGT" => "C", "TGA" => "_", "TGG" => "W", "CTA" => "L",
              "CTC" => "L", "CTG" => "L", "CTT" => "L", "CCA" => "P",
              "CCC" => "P", "CCG" => "P", "CCT" => "P", "CAC" => "H",
              "CAT" => "H", "CAA" => "Q", "CAG" => "Q", "CGA" => "R",
              "CGC" => "R", "CGG" => "R", "CGT" => "R", "ATA" => "I",
              "ATC" => "I", "ATT" => "I", "ATG" => "M", "ACA" => "T",
              "ACC" => "T", "ACG" => "T", "ACT" => "T", "AAC" => "N",
              "AAT" => "N", "AAA" => "K", "AAG" => "K", "AGC" => "S",
              "AGT" => "S", "AGA" => "R", "AGG" => "R", "GTA" => "V",
              "GTC" => "V", "GTG" => "V", "GTT" => "V", "GCA" => "A",
              "GCC" => "A", "GCG" => "A", "GCT" => "A", "GAC" => "D",
              "GAT" => "D", "GAA" => "E", "GAG" => "E", "GGA" => "G",
              "GGC" => "G", "GGG" => "G", "GGT" => "G");

    $codon = uc($codon);

    if (exists($aa{$codon})) {
        return $aa{$codon};
    } else {
        print STDERR "Bad codon \"$codon\"!\n"; 
        exit;
    }
}

print &codon2aa("GaA") . "\n";

Ein Hash bietet sich doch irgendwie an, oder?

Bei Funktionsaufrufen sollte man ein "&" voranstellen (z.B.: &codon2aa("GaA")), um "lose Wörter" ("barewords") im Skript zu vermeiden.

Gruß
Last edited: 2010-06-24 21:15:15 +0200 (CEST)

View full thread my richtig setzen