For something like this, I'd typically split on white space and pick the values out rather than creating a regex. Assuming there is always white space between all the items, the following would work with your example data.
while (<DATA>) {
# Remove white space at end of line;
s/\s+$//g;
# Get length of line
my $length = length;
my @items = split;
# If line is long, want the internal items,
# if shorter want the last ones
# 50 works with the example.
if ( $length > 50 ) {
print join( "\t", @items[ 1, $#items - 4, $#items - 3 ] ), "\n
+";
}
else {
print join( "\t", @items[ 1, $#items - 1, $#items ] ), "\n";
}
}
__DATA__
605 abc xxx 410.00 mV < 450.98 mV < 490.00 mV
606 bcd yyy -46.50 dB < 50.70 dB
607 are zzz 50.00 dB < 58.48 dB
Of course, you can capture the values of interest rather than printing them.
-albert
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.