[ale] perl and environment stuff

Mike Fletcher fletch at phydeaux.org
Tue Dec 26 23:39:31 EST 2006


James P. Kinney III wrote:
> The open command looks like:
>
> open (FILEOUT, ">>$filetowrite") || die "Crud! $filetowrite puked $!\n";
> print FILEOUT "$stuff\n";
> close FILEOUT;
>
> And $filetowrite is defined earlier and exists on the system (It's
> the /etc/cups/printers.conf file for the morbidly curious)
>
> The only thing I can think is that the remote users are getting a
> different environment that drops the ">>" for a ">". But it's all bash
> login shells. 
>
> Suggestions on where to look?
>   
Something else is wrong then; append mode (">>") is append mode and 
nothing in the environment should change that.


I'd look at anything else that may be manipulating the file (maybe 
something's calling lpadmin that you're not aware of, and the two of you 
are bumping heads).  Also consider adding in extra debugging prints, 
such as dumping the size of $filetowrite from a stat() call before and 
after your opens.  If all else fails, use strace (possibly with -f to 
follow forks) to record what sequence of system calls are being made in 
the two different environments and see what's different between the two.


(And stylistic aside: the three argument form of open is preferred these 
days, presuming you're using a recent enough Perl that it works.  So 
you'd want:

open( FILEOUT, ">>", $filetowrite ) or die "Append to '$filewrite' 
failed: $!\n";

instead of the two argument form.  Also another minor nit, it's slightly 
more efficient to call

print FILEOUT $stuff, "\n";

with two arguments, as that'll avoid creating a temporary copy of $stuff 
and the newline and passing that to print.)







More information about the Ale mailing list