Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts

    How to creat a dynamic html using perl

    I know that in php, we can bring up a dynamic html by using the below code:

    Code:
    $theResults=<<<EOD
    <html>
    ......
    </html>
    EOD;
    
    echo "$theResults";
    Is there a way we can do this in perl as well? My server does not allow php for security reasons. Thank you.

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    That's called a "Here Document" and yes Perl has them as well and is only 1 of many ways you could output html.

    http://www.stonehenge.com/merlyn/UnixReview/col12.html

  • Users who have thanked FishMonger for this post:

    camaross (03-27-2011)

  • #3
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Thank you very much for the help. I tried the below code many times. Every time I got an error message:
    "500 Internal Server Error. An internal server error has occured."

    Code:
    my $name = $form{"name"} ;
    
    if ($name eq "") {
    
    $a = <<END;
    
    <html>
    
    <head></head>
    
    <body>Please go back and enter your name!</body>
    
    </html>
    
    END
    
    print $a;
    
    exit;
    
    }
    Any idea what is wrong here? Thank you.



    Quote Originally Posted by FishMonger View Post
    That's called a "Here Document" and yes Perl has them as well and is only 1 of many ways you could output html.

    http://www.stonehenge.com/merlyn/UnixReview/col12.html
    Last edited by camaross; 03-27-2011 at 11:33 PM.

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Did you print the content type header?

    Personally, Id use the CGI module.

    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use CGI;
    use CGI::Carp qw( fatalsToBrowser );
    
    my $cgi = CGI->new;
    
    print $cgi->header, $cgi->start_html,
          $cgi->p('Please go back and enter your name!'),
          $cgi->end_html;

  • Users who have thanked FishMonger for this post:

    camaross (03-28-2011)

  • #5
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Thank you so much for the reply.

    I am new to perl and not familiar with CGI. the above code is just an simplified example. What I really want to do is to bring up a new html with lots of information, such as the original contact form with red texts around fields that are required but are missing dependent on users' input. I have many fields that I want my users to input, so I am thinking to use if for each of the fields.

    I appreciate your kind help very much.


    Quote Originally Posted by FishMonger View Post
    Did you print the content type header?

    Personally, Id use the CGI module.

    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use CGI;
    use CGI::Carp qw( fatalsToBrowser );
    
    my $cgi = CGI->new;
    
    print $cgi->header, $cgi->start_html,
          $cgi->p('Please go back and enter your name!'),
          $cgi->end_html;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •