in reply to Re: Printing contents of file on a HTML page.
in thread Printing contents of file on a HTML page.

Or, if you like brevity:
while (<FIL>) { print; }
(print, like many Perl functions defaults to using the variable $_ if no other arguments are given. The loop stores each line of the file in $_ if it is not asigned to any other variable)

Replies are listed 'Best First'.
Re: Re: Re: Printing contents of file on a HTML page.
by dreadpiratepeter (Priest) on Sep 23, 2002 at 16:15 UTC
    I know. He seemed like a beginner so I wanted to be clear. You could also do:
    print while <FIL>; print join('',<FIL>);
    etc.

    -pete
    "Pain heals. Chicks dig scars. Glory lasts forever."
Re: Re: Re: Printing contents of file on a HTML page.
by Bilbo (Pilgrim) on Sep 23, 2002 at 16:05 UTC
    Sorry - I forgot to log in. That should have read:
    while (<FIL>) { print OUT; }
      Thanks this did work for me except it prints out the file contents on one line in my HTML page:
      wordOnewordTwowordThree Okay this prints out.
      It should print out:
      wordOne wordTwo wordThree Okay this prints out.
      Here is what I used and it works but how can I make the output print the correct way? I have tried the "\n" and <br> in various places but no luck.
      use strict; my $path = "/web/webpage.html"; my $myfile = "/perl/bin/bas.txt"; open FIL, "$myfile" || die "cant open: $!\n"; open OUT, ">$path" || die "Can't open $path for writing: $!\n"; while (<FIL>) { print OUT; } print OUT <<"EOF"; <html> <head> <title>Title</title> </head> <body> <br> Okay this prints out. </body> </html> EOF close OUT || die "Can't close filehandle: $!\n"; close FIL || die "no cant close: $!\n";

        There are many possible solutions for this. One is:

        print OUT "<pre>"; while (<FIL>) { print OUT; } print OUT "</pre>";