P is for Practical | |
PerlMonks |
Re: do-ing of file without \n at the endby sgifford (Prior) |
on Mar 30, 2007 at 16:43 UTC ( [id://607523]=note: print w/replies, xml ) | Need Help?? |
You can't rely on checking $! unless do contains undef. From the docs:
If "do" cannot read the file, it returns undef and sets $! to the error. If "do" can read the file but cannot compile it, it returns undef and sets an error message in $@. If the file is successfully compiled, "do" returns the value of the last expression evaluated. Otherwise $! can contain just random garbage, which is probably what you're running into. Update: To reply to your update, sawoy, perl is probably reading the file just fine, but because $! contains gibberish and you are exiting if it is nonzero, you are exiting anyways. Try using this instead:
That works for me. Note, though, that you need to ensure that $file ends with something true (not undef, 0, or the empty string). If you use this instead: you will only have to make sure it doesn't end with something that evaluates to undef, but there's way I know of to tell the difference between an error and the file simply ending with undef.
In Section
Seekers of Perl Wisdom
|
|