[comp.lang.perl] Perl "do" bug.

clewis@eci386.uucp (Chris Lewis) (02/08/90)

When you

	do 'something';

And "something" isn't in your home directory (though it's directory is in 
@INC), $! is set to "No such file or directory".  Even though perl actually 
did read the file, $@ is zero/null and definitions set therein can be 
referenced.  Sometimes this appears to depend on the contents of the 
perl script, but I've not narrowed it down very far.  Both Perl 2 and 3.

I suspect that this is actually errno being set on the first open attempt
(in your home directory), but isn't being reset on a later successful
open.

Have I missed something?
-- 
Chris Lewis, Elegant Communications Inc, {uunet!attcan,utzoo}!lsuc!eci386!clewis
Ferret mailing list: eci386!ferret-list, psroff mailing list: eci386!psroff-list

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (02/09/90)

In article <1990Feb7.190655.16030@eci386.uucp> clewis@eci386 (Chris Lewis) writes:
: When you
: 
: 	do 'something';
: 
: And "something" isn't in your home directory (though it's directory is in 
: @INC), $! is set to "No such file or directory".  Even though perl actually 
: did read the file, $@ is zero/null and definitions set therein can be 
: referenced.  Sometimes this appears to depend on the contents of the 
: perl script, but I've not narrowed it down very far.  Both Perl 2 and 3.
: 
: I suspect that this is actually errno being set on the first open attempt
: (in your home directory), but isn't being reset on a later successful
: open.

I think your analysis is correct.  I don't think you should rely on the
value of $! at that point though.  The fact that $@ is null means there
was no compilation error.  To indicate successful execution of 'something'
I've been putting a 1; at the end of every 'something' I write.  The you
can just say

	do 'something' || die "Couldn't do something";

To specifically check for whether the file was found you could say

	$foo = do 'something';
	die "Couldn't find something" unless defined $foo;
	die "Couldn't parse something: $@" if $@;
	die "Couldn't run something" unless $foo;

$! is not meant to be anything more than what errno is.  And errno just
reflects the last error on a system call.  Something as complicated as
a path search does a number of system calls.

Larry