Read New Line and print in HTML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • palm
    New Member
    • Feb 2007
    • 27

    Read New Line and print in HTML

    Hi There,
    I've a Perl code that reads a txt file (which has colum data) line by line, but for some reason when I print it in html, it's not printing as colum data. Instead it's printing in one line. This is my Perl code that reads the lines:
    while (<FILE>){
    $line = $line . $_ ;
    }

    and this is my html part:
    <br> $line <br>

    I'm new to both languages and I'm not sure which one is causing the problem. Can some one help me please?

    palm.
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Code:
    while (<FILE>){
       $line .=  "$_<br>" ;
    }
    or:

    Code:
    while (<FILE>){
       print "$_<br>";
    }
    the problem is that you built one long line out of the file then added <br> tags to the one long line, you have to add them for each line you want to break.

    Comment

    • palm
      New Member
      • Feb 2007
      • 27

      #3
      Thanks a lot KevinADC,
      You've solved my problem. I thought when I read the lines, the "\n" can be read too, but it didn't work that way.

      Thanks again.

      Palm.

      Comment

      • miller
        Recognized Expert Top Contributor
        • Oct 2006
        • 1086

        #4
        Originally posted by palm
        I thought when I read the lines, the "\n" can be read too, but it didn't work that way.
        Hi palm,

        The return character "\n" can and is read in your above code. However, return characters are meaningless in HTML. That is why you needed to add <br>'s after ever line.

        - Miller

        Comment

        Working...