in reply to Where oh where should I initialize my vars?

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)

Replies are listed 'Best First'.
RE: Re: Where oh where should I initialize my vars?
by merlyn (Sage) on Oct 26, 2000 at 01:41 UTC
    Ouch. Don't use scalar split. It's marked deprecated, and mangles @_ in the process. Odd that you didn't see that, because you said you were looking through the documentation! {Grin}

    -- Randal L. Schwartz, Perl hacker

      I am having a bad morning here. I checked up the 2nd edition camel - and there was no mention of "deprecated" anywhere, likewise no warning on the @_ mangling either.

      I will now take two asprins and go back to bed.

RE: Re: Where oh where should I initialize my vars?
by runrig (Abbot) on Oct 26, 2000 at 01:45 UTC
    Or:
    warn("Bad Data: [$_]"), next unless tr/\t// == 2; # Do Stuff