Dies ist ein Teil der Arbeit. In diesem Teil versuche ich ein Programm zu schreiben, um einen Hash zu erstellen. Die Schlüssel sind Zugriffsnummern in einer Datei, die Werte sind die gesamten Zeilen. Das Programm warnt mich jedoch. Der Code ist:Wie Sie einem Hash in Perl einen Wert zuweisen
#!/usr/bin/perl
#psuedocode:
#open file1, store uniport accesion as key and the line as value
#open file2, store uniport accesion as key and the line as value which lines contain "IDA"
#compare keys in two hashes, find out matched keys
#print out lines from file2 that match
use strict;
use warnings;
use feature qw(say);
my $infile1 = "geneIDs3_MouseToUniProtAccessions.txt";
my $inFH1;
open ($inFH1, "<", $infile1) or die join (" ", "Can't open", $infile1, "for reading:", $!);
my @array1 = <$inFH1>;
close $inFH1;
shift @array1;
my %geneID1;
for ($a = 0; $a < scalar @array1; $a++){
chomp $array1[$a];
$array1[$a] =~ /.*?\t(.*?)\t.*/;
$geneID1{$1} = $array1[$a];
#say ("$1", '->', "$geneID1{$array1[$a]}"); #test if the hash has been successfully created, however it doesn't
#say $array1[$a]; #test if the program can recognize the elements, it does
}
die Datei geneIDs3_MouseToUniProtAccessions.txt
enthält 1000 Zeilen, so dass die Warnungen sind zahlreich. Die ersten beiden Zeilen sind:
From To Species Gene Name
PNMA3 Q9H0A4 Homo sapiens paraneoplastic antigen MA3
Die Warnung gefällt das:
Use of uninitialized value within %geneID1 in string at match_for_part_III_10.pl line 24.
Q9H0A4->
fand ich die Lösung: Statt while
Schleife verwenden. Es funktioniert nicht nur, es ist auch eleganter. Der neue Code ist:
#!/usr/bin/perl
#psuedocode:
#open file1, store uniport accesion as key and the line as value
#open file2, store uniport accesion as key and the line as value which lines contain "IDA"
#compare keys in two hashes, find out matched keys
#print out lines from file2 that match
use strict;
use warnings;
use feature qw(say);
my $infile1 = "geneIDs3_MouseToUniProtAccessions.txt";
my $inFH1;
open ($inFH1, "<", $infile1) or die join (" ", "Can't open", $infile1, "for reading:", $!);
my %geneID1;
while (<$inFH1>){
$_ =~ /.*?\t(.*?)\t.*/;
$geneID1{$1} = $_;
say ("$1", '->', "$geneID1{$1}");
}
close $inFH1;
Vielen Dank für Ihre unglaubliche Hilfe!
Warnungen = Sie nicht etwas Fall behandeln, wahrscheinlich fehlenden Daten. Warum drucken Sie sie nicht aus und werfen Sie einen Blick darauf. – xxfelixxx
@zdim Andere Teile funktionieren gut. Ich muss '$ a' nicht angeben, bitte lesen Sie den Kommentar von meiner vorherigen Frage https: // stackoverflow.com/questions/46739301/tons-of-use-of-uninitialized-value-innerhalb-genetic-code-in-substitution-iterato –
@ zdim, '$ a 'wird immer deklariert. – ikegami