[LA.pm] calling gzip from within perl

Jeremy Leader jleader at alumni.caltech.edu
Wed Jun 29 13:31:47 PDT 2005


Peter Benjamin wrote:
> At 12:02 PM 6/29/2005, Jeremy Leader wrote:
>>Peter Benjamin wrote:
>>>At 10:21 PM 6/28/2005, David Heayn wrote:
>>>>      open(FILE, "gunzip $fileLoc |") or die "Cannot gunzip '$fileLoc': $!";
>>>>      my @stuff = <FILE>;
>>>>      close(FILE);
>><snip>
>>>Does your script use STDIN?  If so, then
>>>this method of re-using STDIN (the pipe after the filename in
>>>the open) would cause problems.  They share the same /dev/*
>>>file name that STDIN uses.  As it appears to be a CGI script
>>>I suppose you will not be able to re-use STDIN using the |
>>>inside the open.
>>
>>But the snippet of code above doesn't use STDIN.
> 
> You're right, it uses STDOUT.  I should not reply past midnight.
> CGI scripts also use STDOUT to send data back to the web server,
> so the point of reuse still applies, only now to STDOUT.
> 
> Thanks for the correction Jeremy.

But it's gzip's STDOUT which is piped to FILE, it doesn't
affect the script's STDOUT, which is what CGI pipes back
to the client.

So I believe that it's okay to use this idiom (assuming you
use the -c option to gzip, as Eric pointed out), even in a
CGI script.

-- 
Jeremy Leader
jleader at alumni.caltech.edu
leaderj at yahoo-inc.com (work)


More information about the Losangeles-pm mailing list