Regular expressions really aren't the most reliable way to parse XML or HTML. Line breaks can show up anywhere so it is entirely possible to have one of your dd tags split across two lines. You will get the most reliable results if you use one of the many XML or HTML parsers available on CPAN, for example, XML::Twig. These will let you pick out specific elements and their attributes (e.g. the value of attribute "term" for the <dd> element).

To make sure you have one and only one of each number, use a hash. Each time you retrieve a new number, add it as a hash key. When you are done parsing the file, you can extract the list of keys from the hash (see keys) and you will have a unique list of numbers. The pseudo-code looks like this:

# declare your hash my %hGoIds; # read in the file using XML::Twig or line by line # if you must. Now for each number you find: $hGoIds{$go_id} = 1; # when you have read in all of the lines and found all of # the numbers, extract your keys my @aKeys = keys %hGoIds;

For more information on hashes, see perldata and search for the word hash (for some reason it isn't in the table of contents).

Best, beth


In reply to Re: Help regarding regular expression by ELISHEVA
in thread Help regarding regular expression by chavanak

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.