Hi monks

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.