Dear all, I am familiar with how to read in a table, parse the columns and create hashes holding the data . However, now I am dealing with input files where related variables are contained in subsequent rows as opposed to in the same column. Now, I am having a seemingly simple problem that my parsing logic doesn't seem to work anymore. It might be an error to do with when I initialize my variables, or what? Any help is appreciated.

sample input data

# UNIQUE-ID - GJDZ-5046 TYPES - BC-4 TYPES - Unclassified-Genes COMMON-NAME - STM14_5042 ACCESSION-1 - STM14_5042 CENTISOME-POSITION - 90.96536 COMPONENT-OF - CHROMOSOME-1-100 COMPONENT-OF - TUJDZ-2494 COMPONENT-OF - CHROMOSOME-1 LEFT-END-POSITION - 4430254 PRODUCT - GJDZ-5046-MONOMER RIGHT-END-POSITION - 4430427 TRANSCRIPTION-DIRECTION - - // UNIQUE-ID - GJDZ-1101 TYPES - BC-4 TYPES - Unclassified-Genes COMMON-NAME - focA ACCESSION-1 - STM14_1100 CENTISOME-POSITION - 20.85712 COMPONENT-OF - CHROMOSOME-1-23 COMPONENT-OF - TUJDZ-587 COMPONENT-OF - CHROMOSOME-1 LEFT-END-POSITION - 1015797 PRODUCT - GJDZ-1101-MONOMER RIGHT-END-POSITION - 1016774 TRANSCRIPTION-DIRECTION - - //

snippet of code that gives wrong results

my %Ho14Loc2GeNm; while(my $lines=<IN>){ my $cycID14; my $cycLoc14;my $cycNm14; next unless (($lines =~/^UNIQUE-ID/) || ($lines=~/^ACCESSION-1 +/)|| ($lines=~/^COMMON-NAME/)); chomp $lines; if ($lines =~ /^UNIQUE-ID/){ $lines=~/(GJDZ-[0-9]+)/; $cycID14=$1; } if ($lines =~ /^COMMON-NAME/){ $lines=~/COMMON-NAME - (\S+)/; $cycNm14=$1; } if ($lines =~ /^ACCESSION-1/){ $lines=~/(STM14_[0-9]+)/; $cycLoc14=$1; } if (defined($cycLoc14)){ $Ho14Loc2GeNm{$cycLoc14}=$cycNm14; } } print Dumper(%Ho14Loc2GeNm); close(IN);

In reply to Parsing line by line by AWallBuilder

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.