Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Outputing HTML files

by Anonymous Monk
on Aug 22, 2001 at 04:20 UTC ( [id://106833]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I'm trying to write a script that will take in a string from an html form, then run an if statement which will compare it to another string and if the two strings are equal, it will generate an html file. Here is code I have so far. What I don't know is the syntax for generating an html file.
#!/user/local/bin/perl -wt use strict; use CGI ':standard'; my $agentname; $agentname = param('agentname'); if($agentname eq 'Joe Bob') { output to browser joebob.html }

Any help with this matter would be greatly appreciated.

Replies are listed 'Best First'.
Re: Outputing HTML files
by Yohimbe (Pilgrim) on Aug 22, 2001 at 04:34 UTC
    In the spirit of perl, there are dozens of ways to do it, but the most appropriate depends on the rest of your design. This question has been answered quite a few times here
    --
    Jay "Yohimbe" Thorne, alpha geek for UserFriendly
      Please use the linking conventions. When you give a full URL, if someone follows your link but is using this site under a different name, they will lose their login.

      That is instead of constructing the above link with either of:

      <a href="http://www.perlmonks.com/index.pl?node_id=69097">here</a> [http://www.perlmonks.com/index.pl?node_id=69097|here]
      it is best if you use:
      [id://69079|here]
      And a tip for those who don't want to accidentally post as Anonymous Monk. Set your personal theme to anything other than the site default. Then when you follow a link that can leave you logged out, you will see everything change colour and know what happened...
(ichimunki) Re: Outputing HTML files
by ichimunki (Priest) on Aug 22, 2001 at 19:16 UTC
    Before your big set of if statements, you probably want to start the page. This way you won't have to do it for each if. Then you want to end it after the ifs. So you end up with code like:
    #!/usr/bin/perl -w use strict; use CGI ':standard'; my $agentname = param('agentname') || 'default'; print header(), start_html( -title => 'Joe Bob' ); if( $agentname eq 'Joe Bob' ) { print h1( 'Header for Joe Bob' ), p( 'Text for Joe Bob' ); } else #default { print h1( 'Default' ); } print end_html();
Re: Outputing HTML files
by jryan (Vicar) on Aug 22, 2001 at 04:58 UTC

    First of all, you forgot to create a new CGI object, like this:

    my $query = new CGI;

    As for your question either of these will work:

    print "Content-type: text/html\n\n";

    or

    print $query->header();
      You don't need to create an object when using CGI.pm's function oriented style. S/He imported :standard.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-26 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found