Hello SandraA, and welcome to the Monastery!
Please enclose your code in <code> ... </code> tags, that will make it much easier to read (and $linearray[2] will display correctly).
Your approach is essentially the same as that given by muba, and it should work fine, except:
- You are printing the line only if the third field is less than the threshold, but your original specification was: to print the first one if the third one was larger than my threshold (underlining added). See perlop#Relational-Operators.
- You are splitting on "\t", which is fine as long as the data fields are always separated by single tabs. But splitting on whitespace, using /\s+/ or the equivalent ' ', is probably safer. See split.
...is there some smarter and better way?
Well, if you’re into one-liners, then (assuming your data is in, say, a file called “data.txt” in the current directory) you can do this:
>perl -anE "BEGIN { $threshold = shift; } say $F[0] if $F[2] > $thresh
+old;" 1e-50 data.txt
The -a, -n, and -E switches are explained in perlrun. But code stored in a file is, IMO, easier to debug, reuse, and maintain.
Hope that helps,
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.