Click to See Complete Forum and Search --> : The Perl print statement...


Mike Burdick
05-23-2005, 01:45 PM
This regards the print function:

Let’s say I need to print some html code using a Perl script. Example:


print <<"EOT";
<HTML>
<HEAD>
<TITLE>window_title</TITLE>
.
.
.
EOT

Now this will print everything out with carriage returns etc. But what if I wanted everything printed out in one line. I know I can put each line in a print statement without a newline character but is there a way I can do it as a group?

Thanks

CyCo
05-23-2005, 05:00 PM
...there are many, many ways to utilize the print statement...

is this what you're talking about?

print '<HTML><HEAD><TITLE>window_title</TITLE>';

Mike Burdick
05-23-2005, 06:49 PM
Cyco,

No... I was hoping to avoid putting it in individual print statements or in a line like you suggested. I just wanted it to print out in one line. I take it that the print <<"EOT"; method reads carriage returns as newline characters.
:(

Nedals
05-23-2005, 07:35 PM
Something like this?

my $output = <<EOT;
<HTML>
<HEAD>
<TITLE>window_title</TITLE>
.
.
.
EOT
$output =~ s/\n/ /g; ## replace all \n's with a space (maybe?)
print "$output\n";

Charles
05-23-2005, 07:55 PM
My solution would be#!c:\perl\bin\perl.exe

use CGI;
my $q = CGI->new();

print $q->header,
$q->start_html (-title=>'Window Title'),
$q->h3 ('Window Title'),
$q->end_html;But then I've a thing for the CGI.pm module.

Scriptage
05-24-2005, 02:03 PM
Yeah but it's not easy and it's not on one line, so that's a waste of time isn't it Charles?

Charles
05-24-2005, 03:45 PM
The output, however, is on one line. I thought that's what we were after.

The syntax takes a little getting used to, but just a little.