The stupid question is the question not asked | |
PerlMonks |
Between-text range operator problemby jlongino (Parson) |
on May 17, 2002 at 01:01 UTC ( [id://167160]=perlquestion: print w/replies, xml ) | Need Help?? |
jlongino has asked for the wisdom of the Perl Monks concerning the following question:
I came across a situation similar to this while working on a project. It is not a large project, but the program involved will be kicked off every 5 minutes. To my dismay, the "integrity" of the input files is not of the highest standards, but then they do originate from a governmental source.
The program opens several files, and is to grab the text between header/footer tags (they're not html) including the header/footer. I thought that using the range operator would be perfect but that's when I got hit by the "integrity" factor. Apparently it is not uncommon for a footer to be left off when it is the last section in a file. So much for elegance. My question is, is there a clever/elegant solution to this problem (i.e., slight modification to the range statement) or will it require a more brute force approach? I'm not asking that anyone rewrite the entire program to make it work, I can do that myself. It seems to me that this must be a common problem and that the use of the range operator as I've done is too fragile for any but the most controlled circumstances.
file2.txt:
file1.txt: file3.txt: Program: Output: I tried what seemed like reasonable approaches, but none of them worked, such as the following and variations thereof: if ((/$beg/ .. /$end/) or (/$beg/ .. eof())) { Thanks much, --Jim
Back to
Seekers of Perl Wisdom
|
|