newline problem with messy output - v simple problem 
Author Message
 newline problem with messy output - v simple problem

Hi,

My script fills a variable with the output of a log file. The variable
is then output into html. Although I am sure it is simple, I cannot
work out how to format the output so it contains line ends etc. where
it should do.

All code examples appreciated - thanks.

The output looks like this:
[snip]
Writing out javascript code Aug-23 16:30:22 DEBUG:
upload_confirmation.jsp tolFile Name : i_10x8_sort_down_grey file
extension : gif Aug-23 16:30:22 DEBUG: upload_confirmation.jsp tolFile
Name : i_10x8_sort_up_grey file extension : gif Aug-23 16:30:22 DEBUG:
upload_confirmation.jsp tolFile Name : i_11x12_cadministrator file
extension : gif Aug-23 16:30:22 DEBUG: upload_confirmation.jsp tolFile
Name : i_11x12_padministrator file extension : gif Aug-23 16:30:22
DEBUG: upload_confirmation.jsp tolFile Name : i_11x12_puser file
extension : gif Aug-23 16:30:22 DEBUG: upload_confirmation.jsp tolFile
Name : i_11x13_company file extension : gif Aug-23 16:30:22 DEBUG:
upload_confirmation.jsp tolFile Name : i_11x19_status_trans_hdr file
extension : gif Aug-23 16:30:22 DEBUG:
[snip]

The Perl:

#! /usr/bin/perl

use CGI qw(param);

$host= param("host");
$log= param("log");
$lines= param("lines");
$output= `rsh $host -l dmadmin tail -$lines $log`;

print "Content-type: text/html\n\n";
print "<html><body bgcolor='#FFFFFF' text='#000000'>";
print "<font face='Verdana, Arial, Helvetica, sans-serif' size='1'
color='#999999'>";

print "$output\n";

print "<html><body><h1>End";
print "</h1></body></html>\n";



Sun, 16 May 2004 12:12:10 GMT  
 newline problem with messy output - v simple problem
Hi Big Pig,


Quote:
> My script fills a variable with the output of a log file. The variable
> is then output into html. Although I am sure it is simple, I cannot
> work out how to format the output so it contains line ends etc. where
> it should do.

> The output looks like this:
> [snip]
> Writing out javascript code Aug-23 16:30:22 DEBUG:
> upload_confirmation.jsp tolFile Name : i_10x8_sort_down_grey file
> extension : gif Aug-23 16:30:22 DEBUG: upload_confirmation.jsp tolFile
> Name : i_10x8_sort_up_grey file extension : gif Aug-23 16:30:22 DEBUG:
. . .

> print "$output\n";

> print "<html><body><h1>End";
> print "</h1></body></html>\n";

Can it simply be that the Web server ignores end of line sequences, and if
you want to force formatting, you have to make your Perl replace, e.g.,  LF
with <BR> in $output?

(At a guess, without me bothering to test this - or knowing much HTML:

    $output =~ s/\012/<BR>/g;

or something like that.)

Hope this helps,
Clyde



Sun, 16 May 2004 14:55:43 GMT  
 newline problem with messy output - v simple problem

Quote:

> I cannot work out how to format the output so it contains
>line ends etc. where it should do.

Replace the following line:
Quote:
>print "$output\n";

with this one:
print "<pre>$output</pre>\n";
to tell the browser to use the linebreaks in the
original data.

Regards,
Helgi Briem



Sun, 16 May 2004 15:34:50 GMT  
 newline problem with messy output - v simple problem


Quote:
> Hi,

> My script fills a variable with the output of a log file. The
> variable is then output into html. Although I am sure it is simple,
> I cannot work out how to format the output so it contains line ends
> etc. where it should do.

> All code examples appreciated - thanks.

> The output looks like this:
> [snip]

The output of the log file is plain text, so the simplest is to just
use:

print "Content-type: text/plain\n\n";
print "$output\n";

without the HTML markup and the HTML rendering of the text.

If you want to add other HTML around the output, then you will need to
use one of the other solutions.

--
EBC



Sun, 16 May 2004 20:39:39 GMT  
 newline problem with messy output - v simple problem


Quote:
> Hi,

> My script fills a variable with the output of a log file. The variable
> is then output into html. Although I am sure it is simple, I cannot
> work out how to format the output so it contains line ends etc. where
> it should do.

Nothing to do with Perl and everything to do with HTML.

[snipped log]

Now for the Perl bit....

Quote:

> #! /usr/bin/perl

Make that

#!/usr/bin/perl -wT
use strict;



Mon, 17 May 2004 11:05:14 GMT  
 newline problem with messy output - v simple problem
Thanks everyone - I used Helgi's solution as I need to include other
HTML. Worked perfectly.


Mon, 17 May 2004 11:06:39 GMT  
 newline problem with messy output - v simple problem

Quote:

> Hi,

> My script fills a variable with the output of a log file. The variable
> is then output into html. Although I am sure it is simple, I cannot
> work out how to format the output so it contains line ends etc. where
> it should do.

> All code examples appreciated - thanks.

#!/usr/bin/perl -wT
use CGI qw(param);
print q[Content-type: text/html

<html>
<body bgcolor="#FFFFFF" text="#000000">
<font face="Verdana,Arial,Helvetica,sans-serif"
      size="1" color="#999999">
];
system("rsh", param("host"), qw(-l dmadmin),
    qw(tail), "-".param("lines"), param("log"));
print qq[</font></body></html>\n];
__END__

--
Klein bottle for rent - inquire within.



Fri, 21 May 2004 04:37:07 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. IPC + fork()s + messy output

2. newbie - messy output from system command?

3. Problem with values - simple problem

4. A simple problem befuddling my simple head

5. Strange problem with newline (\r\n) under Win32

6. newline problem with formatted write

7. format picture fields with newlines problem

8. Newline problem

9. Problem checking for newline in $_ input line

10. newlines and query -> param / problem with apostrophes

11. Easy regular expression problem - matching characters and newline at the same time

12. MIME-Tools - MIME::Entity - extra newline problem

 

 
Powered by phpBB® Forum Software