Can't insert newline 
Author Message
 Can't insert newline

I have a cgi script that prints the tail of a log file to html file.  
But when the output is printed on the webpage no newline characters are
inserted.  The contents of the log file are of this format:

Thu Jun 13 07:46:23 CDT 1996 0.29 seconds to ftp
Thu Jun 13 07:46:25 CDT 1996 0.34 seconds to ftp
etc...

But the output has them strung together.  How can I fix this problem?

Here is the part of the code that does the tail and prints it:

#Looking at tail of ftp.log
$buf = `tail $logfile`;
print $buf;

Thanx
Chuck Rickard



Mon, 30 Nov 1998 03:00:00 GMT  
 Can't insert newline

[courtesy copy e-mailed to author(s)]



?But the output has them strung together.  How can I fix this problem?
?Here is the part of the code that does the tail and prints it:
?
?#Looking at tail of ftp.log
?$buf = `tail $logfile`;

Try adding the following right here:
$buf =~ s/\n/\<BR\>\n/go;

?print $buf;

-----

N.D.U.S. UNIX Sys. Admin.    http://abattoir.cc.ndsu.nodak.edu/~nem
"Perl did the magic.  I just waved the wand." - Me



Mon, 30 Nov 1998 03:00:00 GMT  
 Can't insert newline

: I have a cgi script that prints the tail of a log file to html file.  
: But when the output is printed on the webpage no newline characters are
: inserted.  The contents of the log file are of this format:

: Thu Jun 13 07:46:23 CDT 1996 0.29 seconds to ftp
: Thu Jun 13 07:46:25 CDT 1996 0.34 seconds to ftp
: etc...

: But the output has them strung together.  How can I fix this problem?

: Here is the part of the code that does the tail and prints it:

: #Looking at tail of ftp.log
: $buf = `tail $logfile`;

$buf =~ s/\n/<BR>\n/g;

: print $buf;

--
  Tad McClellan,      Logistics Specialist (IETMs and SGML guy)

  Interesting trivia: If you took all the sand in North Africa and spread
     it out... it would cover the Sahara desert.



Mon, 30 Nov 1998 03:00:00 GMT  
 Can't insert newline


Quote:
>I have a cgi script that prints the tail of a log file to html file.  
>But when the output is printed on the webpage no newline characters are
>inserted.  The contents of the log file are of this format:

>Thu Jun 13 07:46:23 CDT 1996 0.29 seconds to ftp
>Thu Jun 13 07:46:25 CDT 1996 0.34 seconds to ftp
>etc...

>But the output has them strung together.  How can I fix this problem?

>Here is the part of the code that does the tail and prints it:

>#Looking at tail of ftp.log
>$buf = `tail $logfile`;
>print $buf;

You can do something like set the content-type of the document you're
generating to text/plain or you can do something like this to make it
safe html with line breaks:

  for (`tail $logfile`)
  {
    s/&/&amp;/g;
    s/>/&gt;/g;
    s/</&lt;/g;
    s/"/&quot;/g;

    print '<br>', $_;
  }

or you can put <pre></pre> around this section of output and forget the
<br> (which should make it render in a fixed width font on the browser as
well)

Hope this helps,

Mike

--

http://www.*-*-*.com/ ~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.{*filter*}com.net/~mike/     |                   65 F3 3F 1D 27 22 B7 41



Mon, 30 Nov 1998 03:00:00 GMT  
 Can't insert newline

: I have a cgi script that prints the tail of a log file to html file.  
: But when the output is printed on the webpage no newline characters are
: inserted.  The contents of the log file are of this format:

: #Looking at tail of ftp.log
: $buf = `tail $logfile`;
: print $buf;
  ^^^^^^^^^^^
  print "$buf\n";

Hope this helps.

Nate



Mon, 30 Nov 1998 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. insert newlines in a long string

2. How to insert a newline in Perl

3. How to insert newline break into a long string

4. Insert newline into long string

5. Inserting a 'newline' in arrays?

6. Text widget's 'insert', and jpg images

7. insert 'n' amount of questions

8. Replacing multiple occurences of newline chars with a single newline char

9. Newlines and regex's

10. Can't figure out how to remove newlines

11. $\ on Win95 - can't get unix newline

12. Regexp's and Newlines

 

 
Powered by phpBB® Forum Software