printing witghout print whatever\n";

They have: 314 posts

Joined: Nov 1999

Hi,

How can you print a html page without having to go:

print "\n";
print "

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

Well you can always have the html file as an external text file.

open FILE "> html.txt";
@lines = ;
close FILE;

foreach $line(@lines) {
print "$line\n";
}

or the way to print formatted html within your script...

print >>"HTML";

HTML

I don't know if the last part is correct. I can't find it on a website and I left my books at home. I can't test perl on this laptop neither...so try it out and if it don't work I am sure someone will correct my post, and I will change it when I get to my books.

VulKen
Who's Bad

Pimpin like a pimp with an electrofied pimpin machine!

They have: 193 posts

Joined: Feb 2000

I see two answers to your question: 1) A different "method," or 2) a template system.

Answer One:

Try using print qq| |; Using that will make it so you don't have to exscape the " or other such characters.

Example:

print qq|<html>
<head>
  <title>My Title</title>
</head>
<body>
  This is were I place the "body."
</body>|;
'

The only catch, you have to exscape a pipe |. To do this, simply type "\|".

Answer Two:

You can use a template. Create a sub routine created "build_html." Example:

sub build_html {
local ($title, $body) = @_;
print qq|
  <html>
   <head>
    <title>$title</title>
   </head>
   <body>
    $body
   </body>
  </html>
|;
}
'

To use this, just call a subroutine with the $title and $body (or whatever variables ou want to you). Example:

$title = qq|This is my web page's title.|;
$body = qq|This is my web page's body content.|;
&build_html($title, $body);
'

If you wish for any help to customize answer two's colution to your site, don't hesitate to ask. Smiling

Hope that helped.

Richard

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

They have: 453 posts

Joined: Jan 1999

It's always a good idea to use templates.

Try to use fast-templates, a ready made module that does everything you need.

For short texts you could use the (already mentioned) "here-document" approach, but that's not very flexible Sad

They have: 314 posts

Joined: Nov 1999

Ok, thanks people Smiling

The one i was thinking of when I posted this was Vulkens so I will try that out. i really didn't understand the template one so I will leave that to the pro's Laughing out loud
Thanks

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.