rootstock has asked for the wisdom of the Perl Monks concerning the following question:

hi, this is the first time i use perl for programming cgi, i got some codes example from a book
use CGI qw(:standard) print header(),start_html ("resource input"),h1("recource");

then i tried it on my pc,the problem occur at the second line
error message
No comma allowed after filehandle at C:\DOCUME~1\gzcnc\LOCALS~1\Temp\dir25.tmp\a .pl line 2.
what is the problem?
thanks

update (broquaint): moved to SoPW + dropped <br> tags in the code

Replies are listed 'Best First'.
Re: cgi question
by gellyfish (Monsignor) on Jun 18, 2003 at 14:12 UTC

    After having fixed the missing semicolon after the use CGI ... it worked fine for me, producing:

    Content-Type: text/html; charset=ISO-8859-1
    
    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE html
    	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"><head><title>resource input</title>
    </head><body><h1>recource</h1>
    
    What version of CGI.pm and Perl are you using?

    /J\
    
Re: cgi question
by hardburn (Abbot) on Jun 18, 2003 at 14:09 UTC

    Perl thinks you're doing something like this:

    open(FH, '>foo.txt') or die $!; print FH "bar"; close(FH);

    Which prints to a file instead of STDOUT. Try explicitly passing the filehandle in your code, e.g.:

    print STDOUT header(),start_html ("resource input"),h1("recource");

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

Re: cgi question
by edoc (Chaplain) on Jun 18, 2003 at 14:14 UTC
    use CGI qw(:standard) print header(),start_html ("resource input"),h1("recource");

    Just gotta check.. was this code copied out of your script? ..it's missing a semicolon (;) at the end of the first line.

    cheers,

    J

Re: cgi question
by kutsu (Priest) on Jun 18, 2003 at 14:13 UTC
      Just because the original poster forgot a semi-colon does not mean that we should persuade them from using CGI.pm's HTML generation methods, IMHO. All preferences aside, at least promote header:
      use strict; use warnings; use CGI qw(header param); print header(); print "<p>resource input</p>\n"; print "<h1>resource</h1>\n";
      But for something this small, why type all of that when what the OP had (with that semi-colon in the right place) works just fine?

      Kudos, howver, for promoting Ovid's stuff. ;)

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)