[comp.lang.perl] requires vs do expr.

russell@ccu1.aukuni.ac.nz (Russell J Fulton;ccc032u) (03/06/91)

I have a set of system administration scripts written in perl. All these 
scripts use a single file to define certain parameters. eg. name of password
file, lock files etc.

I have tried to include this file into the other scripts with both require and 
do but have found querks which ever way I did it. 

Firstly 'do expr' gives no indication of failure if the file indicated by 'expr'
does not exits or can not be opened. (Is this a bug or a feature?)

'requires expr' insists that the last expression in the file be non zero. (I had
to add a '1;' to the end of the file to get it to work. Requires does complain
if it can't open the file.

These are as much as anything a shortcoming of the documentation 
so please can the next edition of the book have some more details on how to
use require and a warning to test for the presence of the target of 'do expr'.

Cheers, Russell.
-- 
Russell Fulton, Computer Center, University of Auckland, New Zealand.
<rj_fulton@aukuni.ac.nz>

composer@chem.bu.edu (Jeff Kellem) (03/06/91)

In article <1991Mar6.032242.4660@ccu1.aukuni.ac.nz> russell@ccu1.aukuni.ac.nz
	(Russell J Fulton;ccc032u) writes:
 > I have tried to include this file into the other scripts with both require
 > and do but have found querks which ever way I did it.
 >
 > Firstly 'do expr' gives no indication of failure if the file indicated by
 > 'expr' does not exits or can not be opened. (Is this a bug or a feature?)

Actually "do EXPR" does give indication of an error via $@.  In the book,
look at page 115.  So, you can check $@ to see if the "do EXPR" succeeded
or failed.  Something like:

	die $@ if $@;

 > These are as much as anything a shortcoming of the documentation so please
 > can the next edition of the book have some more details on how to use
 > require and a warning to test for the presence of the target of 'do expr'.

Yeah, it probably should have a better pointer in the documentation, since
$@ isn't mentioned in the description of "do EXPR".  As for "require" it
is documented using a Perl implementation of "require".. ;-)

Cheers...

			-jeff

Jeff Kellem
Internet: composer@chem.bu.edu