I'm interested in it's R-score and protein name. The tricky part is the variable number of occurences of the protein name. ... So I want to fetch ..."

And on fetching the various chunks, what do you need to do with them? How do you want to organize, manipulate or summarize them? Is each "candidate" uniquely identified by the "candidate number"? If so, do you want a simple listing that shows, e.g.

candidate-number R-score [protein-name ...]
What you intend to do with the data is an important issue, because it should determine how you set up the appropriate data structure for the task. For example, if the candidate numbers are unique and sequential, you probably want an array of hashes:
my @candidates; # should use a hash instead, if my $c_id; # the numbering has lots of big gaps while (<>) { if ( /CANDIDATE\s+(\d+)/ ) { $c_id = $1; } elsif ( /DNA\s+.Note.\s*(\S*.*)/ ) { my $proteins = $1; my @p_set = (); while ( $proteins =~ /\[(NP\s+\d+)\]/g ) { push @p_set, $1; } $candidates[$c_id]{proteins} = [ @pset ]; } elsif ( /R-score\s*=\s*([.\d]+)/ ) { $candidates[$c_id]{rscore} = $1; } }
If you're still learning about data structures and references, I'm sure the relevant man pages will supply any other details you may need (perlreftut, perldsc). Use Data::Dumper as well, of course.

In reply to Re: regex with variable input by graff
in thread regex with variable input by BioGeek

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.