Hello all: I'm just starting to learn CGI (about 3 days into it) and I have a few questions about the following script called "image_fetch.cgi" (it's example 3-4 in O'Reilly's "CGI Programming with Perl" by Guelich, Gundavaram & Birznieks, pp. 60-61). Sorry there are so many questions, but I'm a little confused.
1) This script doesn't really "translate" from a jpeg to a PNG, does it? The $image_type is simply for the header, right? I got confused because the book says, "So we will provide a high-color, high-detail PNG if possible, or a JPEG otherwise" but it seems like the script is just dumping the data untouched right to STDOUT. 2) More description: "If a user calls this with http://localhost/cgi/image_fetch.cgi/new_screenshot.png, he or she will actually get new_screenshot.png or new_screenshot.jpeg depending on what the browser supports." I can see that the script is pulling the filename from $ENV{PATH_INFO} but could this data also be retrieved from @ARGV? I tried a version with @ARGV, but it didn't seem to work, and I wasn't sure if it was due to @ARGV or me. (By the way, it would be smart to use File::Basename for this type of thing, wouldn't it? And is that why there are extra parentheses around the my $basename declaration? It's not in a list context, is it?) 3) The Camel and the Pocket Reference both say that binmode needs a filehandle. I'm guessing the Perl in the Guelich et al book is a slightly older version....? So I should expect a few more of these syntax differences as I go through the book? (I actually never got this version of the script to run, even with setting up some directories and files, but managed very well with the one in the Camel, p. 686.) 4) When I test for syntax errors on the command line, I get the following: Too late for "-T" option at image_fetch.cgi line 1. I'm using Perl 5.6.0 and Apache 1.3.20 on Mac OS 10.1. Thanks in advance for your help. I'm subscribed in digest form, so you might want to "Cc:" me in the reply. Harvey Quamen ---<script>----- #!/user/bin/perl -wT use strict; my $image_type = $ENV{HTTP_ACCEPT} =~ m|image/png| ? "png" : "jpeg"; my ( $basename ) = $ENV{PATH_INFO} =~ /^(\w+)/; my $image_path = "$ENV{DOCUMENT_ROOT}/images/$basename.$image_type"; unless ( $basename and -B $image_path and open IMAGE, $image_path ) { print "Location: /errors/not_found.html\n\n"; exit; } my $buffer; print "Content-type: image/$image_type\n\n"; binmode; while ( read( IMAGE, $buffer, 16_384 ) ) { print $buffer; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]