SPUG: Re: generating output with a cgi script

Adam Monsen meonkeys at hotmail.com
Mon Oct 2 15:44:46 CDT 2000

To get your version to work:
A. Use the full pathname for the file. ie:

open(DB_FILE, "/home/httpd/html/test.bib");

B. Looks like you have a couple of typos (no > after $cgi-, misspelled 
"$value") and an unnecessary foreach loop. Instead of:

foreach $value ($cgi-param($name)) {
print " $values\n";

try this...

print $cgi->param($name)."\n";

Here's some hints:
1. You don't need the second "foreach" loop, you're already iterating over 
all the CGI params (see "B").
2. Always "use strict" (along with perl -w and -T if you need it), this 
helps to disallow some unsafe constructs (It would have noted that you never 
use "my", for instance).
3. Use "or die" with your "open(DB_FILE..." this is a key operation, and you 
need to know if it fails.
4. Process the file line by line rather than all at once. This scales 

Good Luck, Yaoxi!

To the gurus: I would appreciate any hints/elucidations on my 
recommendations. Thanks!

>From: "Wu, Yaoxi" To: "'spug-list at pm.org'" Subject: SPUG: generating output 
>with a cgi script Date: Mon, 2 Oct 2000 10:44:28 -0700
>This thing is driving me crazy; I hope someone can enlighten me. Please 
>look at the following short cgi script:
>#!/usr/bin/perl -wT use CGI; $cgi = new CGI; print 
>$cgi->header("text/plain"); open(DB_FILE, "test.bib"); undef $/; $line=; 
>close DB_FILE;
>#### the following was displayed o.k. ##########
>print "Any string.\n"; print $cgi->param('source_type'),"\n";
>#### the following did not show up in the web browser window ###
>print "$line\n"; foreach $name ($cgi->param){ print "$name:\n"; foreach 
>$value ($cgi-param($name)){ print " $values\n"; } }
>This simple script tries to display the content of a two-line text file, " 
>test.bib", and the values of the parameters that the user input from a web 
>page. I don't know why the statement, print "$line\n", displayed nothing, 
>although when the script run off-line and was terminated with 'control-D', 
>the file content was displayed. Also, why the values of the user-supplied 
>parameters could not display in this "foreach" loop, but would display when 
>printing individually? Thanks for any help.
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/

More information about the spug-list mailing list