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.