Hi Perl Gurus I'm struggling with a problem which should be fairly easy to solve on but I can't see the wood for the trees. I have a file consisting of records with 5 fields (delimited by |).e.g.
qw|as|df|gh|kj|dddd
ll|kk|pp|oo|ii|dfghj
eee|ttt|td|fff|ddd|/* gggg
xxx|vvv|c|g|nnn|fff
aaaaaa|hh|qq|ww|iii|zzzz */
ppp|j|x|f|o|zkllk
aaa|g|dde|as|lkjh|mnbv
.
.
and so on
I have a regex set up to search for patterns in the 5th field of each record and print the record out if found. However I want to skip all records between an occurence of /* and */ in the 5th field. This donates the start and end of a comment which I'm not interested in. These comments can span multiple records. Assume that the input file records are ordered such that a /* always occurs before a */.
Here's the code I've got that tries to do this but is not working. The problem is that the loop bit isn't working so the regex is checked for every time. The regex contains some pattern matches that could be inside a comment block. Hence I'm getting information printed that is inside a comment block.
open TXTF,"<$txtf" or die "Can't open $txtf : $!\n";
my $regexp = Regexp::List->new(modifiers => 'i',quotemeta => 0)->list2
+re(@matches);
LOOP: while ($line = <CMDTXTF>) {
@fld = split /\|/,$line;
if ($fld[5] =~ /\/\*/) {
next LOOP until $fld[5] =~ / \*\//;
}
print "$fld[0] $fld[2] sequence=$fld[4] $fld[5]" if $line =~ /$r
+egexp/;
}
close TXTF;
Any help appreciated
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.