Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Basic CGI Question (Moved from Q&A)

by Russ (Deacon)
on Aug 26, 2000 at 10:03 UTC ( [id://29791]=perlquestion: print w/replies, xml ) Need Help??

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

This question was moved from Categorized Questions and Answers
Please do not vote for this node. It will affect the wrong user. Thank You -- Q&AEditors

Ok to start off i would like to say IM NEW TO PERL. so dont laugh at my coding...

#!/usr/bin/perl #---------------------------------------------------------- #Umm in trying this, lets see if it works...<BR> #Trying it, doubt it works..<BR> #---------------------------------------------------------- my $in; if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } else { $in = <STDIN>; } @Texts = ("text1","text2","text3","text4","text5"); print <<ENDhdr; print "Content-Type: text/html\n\n"; print "<html><HEAD><TITLE>Thing...</title></head>"; print "<body><H1>Thing</h1>"; print "<input type=text value=\"$Texts[0]\">\n"; print "<input type=text value=\"$Texts[1]\">\n"; print "<input type=text value=\"$Texts[2]\">\n"; print "<input type=text value=\"$Texts[3]\">\n"; print "<input type=text value=\"$Texts[4]\">\n"; print "<input type=\"submit\" value=\"Submit\" onclick=\"?alpha\">"; ENDhdr sub alpha { sort(@Texts) @Texts = yay; print "$yay"; }

Russ
Brainbench 'Most Valuable Professional' for Perl

Replies are listed 'Best First'.
RE: Basic CGI Question (Moved from Q&A)
by ColtsFoot (Chaplain) on Aug 26, 2000 at 10:55 UTC
    The problem that you are encountering is due to the way that
    you are trying to print the HTML. The line:- print <<ENDhdr; is going to print everything to STDOUT until it finds a line
    the starts with the matching ENDhdr. So you do not require
    the print statements on each of the lines.
    Another point is that you will require the <FORM>...</FORM> tag
    around the input tags.
    Things can be made MUCH easier if you were to use the
    CGI.pm module eg.
    #!/usr/bin/perl # use CGI; $page = new CGI; my $in; if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } else { $in = <STDIN>; } @Texts = ("text1","text2","text3","text4","text5"); print $page->header(); # This outputs the Content-Type stuff print $page->start_html(); print $page->startform; print <<ENDhdr; ..... ..... ENDhdr print $page->endform(); print $page->end_html();
    Try using perldoc CGI to get more info
    Hope this is of some help
Re: Basic CGI Question (Moved from Q&A)
by chromatic (Archbishop) on Aug 26, 2000 at 20:23 UTC
    Definitely look into CGI as ColtsFoot suggests. It will make your life so much easier (after you learn the basics, which shouldn't take too long). Here's a revised start to your script, which uses CGI.pm to get the query string (much, much easier and more robust):
    #!/usr/bin/perl -wT use strict; use CGI; my $page = new CGI; my $in = $page->param('alpha');
    And so forth. I'm not sure what you intend to do with the form or the alpha subroutine. Perhaps you could reply and shed more light on it.
Re: Basic CGI Question (Moved from Q&A)
by ar0n (Priest) on Aug 26, 2000 at 21:58 UTC
    Since you're starting out and all, here's an easier way to populate @Texts:
    @Texts = qw(text1 text2 text3 text4 text5);
    Which just tells perl to treat whatever's in qw(...) as a whitespace delimited list.
    Nifty.

    -- ar0n || Just Another Perl Joe

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://29791]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-20 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found