I'm a relative Perl novice and am trying to write a piece of code which will parse information from a file in this format:
Name(tab)Signal(tab)Present or Absent (P or A) call
Basically it does this by incremeting present or absent counts in anonymous arrays existing as the values in a DBM hash. It then prints the present/absent calls out to two files.
The problem is that the hash seems to basically disappear when I exit the <while> loop which parses the input file and my two output files remain empty.
I'm stumped - any help would be sincerely appreciated.
Example input (1 present and 1 absent call):
sequence1\t7\tP\n
sequence2\t1\tA\n
Code:
#!/usr/bin/perl use warnings; $input = "infile"; $background = "2"; open (INPUT, $input) or die "Cannot open infile!$!"; dbmopen (%PAHASH, "crDB", 0777) or die "Cannot open DBM file!$!"; while (<INPUT>) { next if (/^Gene/) || (/^AFFX/) || (/^2000/); chomp (@linearray = split "\t", $_); $name = shift @linearray; $signal = shift @linearray; $affycall = shift @linearray; #$name =~ s/_.{2,4}$//; if ($affycall eq "P" && $signal>$background) { $$PAHASH{$name}[0]++; } else { $$PAHASH{$name}[1]++; } } open (PRESENT, ">present"); open (ABSENT, ">absent"); foreach $key (keys %PAHASH) { if (defined $$PAHASH{$key}[0]) { print PRESENT "$key\t($$PAHASH{$key}[0] present calls)"; } else { print ABSENT "$key\t($$PAHASH{$key}[1] absent calls)\n"; } } dbmclose %PAHASH; exit;
In reply to Problem with DBM hash of anonymous arrays by travisbickle34
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |