Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How To Use Bootstrap Code in Perl Script?

by golux (Chaplain)
on Feb 16, 2016 at 02:43 UTC ( [id://1155320]=note: print w/replies, xml ) Need Help??


in reply to How To Use Bootstrap Code in Perl Script?

Hi glennpm,

Whatever else you do (and a HEREDOC is perfectly fine for generating the HTML, as is Template Toolkit), the one thing you have to do differently with CGI is print headers, followed by at least a single blank line.

For example:

#!/usr/bin/perl use strict; use warnings; # CGI headers (note two newlines, one for a blank line) print "Content-type: text/html\n\n"; # Now anything else you do is HTML ... print "<body style='background:cyan'>\n"; print " <center>\n"; print " <h1>Hello world!</h1>\n"; print " </center>\n"; print "</body>\n";

BTW, another style I've gotten in the habit of in place of HEREDOCS is to quote a block of text with qq{ ... }, putting colons ':' at the beginning of each line for visual ease of reading, and finally reformat the text to remove the colons and print it out. For example:

# CGI headers (note two newlines, one for a blank line) print "Content-type: text/html\n\n"; # Another way to format HTML my $text = qq{ :<body style="background:cyan"> : <center> : <h1> Hello world! </1> : </center> :</body> }; output($text); # Subroutines sub output { my ($text) = @_; # Reformat the HTML text (remove leading colons ':') $text =~ s/(^\s+:)|((?<=\n)\s+:)|(\s+$)//g; # And output it print $text; }
say  substr+lc crypt(qw $i3 SI$),4,5

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found