Others beat me to the punch, in that you were making the assumption that
every line in your input file would consist of the three arguments separated by a tab character. This brings up a matter of good programming practice - never assume that the data you are being fed meets the rules. So you need to allow for two situations; the first which you have already found, where there are less than the required number of fields; and the case where there may be more than 3.
A quick scan through the split documentation says that when called in the scalar context, it will return the count of the substrings. You may want to put a test in first - something like:
if ( (scalar (split /\t/)) == 3 ) {
# Do our stuff
}
else {
print "Bad data", $_;
}
Updated I should not try to program before my first cup of coffee. Yes,
fastolfe and
runrig picked up the error - the single "=" has been replaced with the "==". (slaps himself silly)
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.