in reply to do-ing of file without \n at the end
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:
#!/usr/bin/perl use strict; use warnings; use vars qw($a); my $file = 'conf.conf'; do $file or die "Can't load $file: $!\n"; print "a is $a\n"; exit 0;
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.defined(do $file) or die "Can't load $file: $!\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: do-ing of file without \n at the end
by sawoy (Initiate) on Mar 31, 2007 at 04:38 UTC | |
by sgifford (Prior) on Mar 31, 2007 at 06:31 UTC | |
by ikegami (Patriarch) on Apr 02, 2007 at 00:34 UTC |