Hi all:
I am new to Perl and having some problems...
I have a txt file that contains data like this.
A B C D
1.0E-1 2.0E-2 3.1E-3 3.0E-9
1.0E-1 2.0E-2 3.2E-3 3.0E-9
1.0E-1 2.0E-2 3.3E-3 3.0E-9
1.0E-1 2.0E-2 3.4E-3 1.0E-1
A B C D are separated by tab.
I would like Perl to capture the C value right before D is larger than 1e-3 (capture Cn-1 when Dn > 1e-3; in this case that would be 3.3E-3), and my code right now looks like this:
open (linedata, "/test.txt");
while (<linedata>) {
($A, $B, $C, $D) = split(/\t/, $_);
print "$A, $B, $C, $D, \n"
}
close (linedata);
I don't really know how to process the "capturing Cn-1" part...
Would someone please give me some insight?
And if I add chomp to my code, the program whined about doesn't return a chomp value, which I don't know the reason. Appreciate to have some insight on chomp, too.
Thank you guys!
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.