read_parfile (version 2.0)

You can also look at:
#! /usr/bin/perl

##############################################################################
#
# SYNTAX: read_parfile parfile param
#
# DESCRIPTION: Gets a parameter from a specified parfile.
#              Note this calls ftool_test to check for errors, so
#              the error handling routines should not call this routine
#              to avoid a recursive loop.
#
# VERSION: 2.0
#
# HISTORY: 0.0 -> 1.0 2/6/97
# HISTORY: Rewrote the error checking part to cope with situations
# HISTORY: where the job.par exists but is unreadable, without going into an 
# HISTORY: infinite loop.
# HISTORY: 
# HISTORY: 1.0 -> 2.0 1999-05-07
# HISTORY: Converted from ksh to perl
#
# CALLS: $UTIL/ftool_test
# CALLS: $FTOOL/pget
#
##############################################################################

($parfile, $param) = @ARGV;

$UTIL = $ENV{"UTIL"};
$FTOOL = $ENV{"FTOOL"};
$JOBPAR = $ENV{"JOBPAR"};

`$FTOOL/pget ./${parfile} ${param}  >stdout$$.log 2>stderr${$}.log`;
$code = $?;

if ( $code != 0 or -s "stderr${$}.log" ) {
    ####################
    # There is an error
    ####################
     
    if ( "$parfile" eq "$JOBPAR" ) {
	######################################################
	# Avoid an infinite loop if the job.par can't be read        
	######################################################
	print "ERROR: Cannot read $JOBPAR\n";
	system("cat stdout${$}.log stderr${$}.log");
    }
    else {
	###################################
	# ftool_test can handle the errors  
	###################################
	system("$UTIL/ftool_test pget $? $0 1 stdout${$}.log stderr${$}.log");
    }
}
else {
    #########################################################
    # No error, remove initial and final quotes and send the 
    # result to stdout
    #########################################################
#    print `sed -e"s/^\'//g" < stdout${$}.log | sed -e"s/\'\$//g"`;
    open(STDOUTF, "<stdout${$}.log");
    while ( <STDOUTF> ) {
	s/^\'//;
	s/\'\$//;
	print;
    }
}

###########
# Clean up
###########
$cnt = unlink "stdout$$.log", "stderr$$.log";

exit 0