Hey monks,
Updating on some chatter yesterday in the CB: I've -again- a
page I'm parsing. The parsing goes wel (with, I admit, a big ugly regex that probably could've been written much shorter), but now I want to assign a rank to each match, ie. the first match should get rank 1, the second match rank 2, ... the n
th match should get rank n.
I came up with this:
my $ranking_dgp = 0;
do {
my $gene = $1;
my $chromosone = $2;
my $score_dgp = $3;
$ranking_dgp = $ranking_dgp + 1;
push @gene_score, [ $gene, $chromosone, $score_dgp, $ranking_d
+gp ];
} while ( $text =~ m{gene\=(ENSG\d+).*?<TD>\s+(\d+|X|Y)\s+</TD>.*?
+<TD>.*?<TD>.*?<TD>.*?<TD>\s(\d.\d+)\s\<\/TD\>}gsm);
print Dumper @gene_score;
but it's one off: my first match gets rank 2. When I look at my output, I also see and understand why, but I can't think of a better way to do it.
$VAR1 = [
undef,
undef,
undef,
'1'
];
$VAR2 = [
'ENSG00000165659',
'13',
'0.738681',
2
];
$VAR3 = [
'ENSG00000184226',
'13',
'0.627447',
3
];
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.