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

You are printing the name of the file not the contents. You need to use the <> operator to read through the file and print out the results. ie:
foreach (my $line = <FIL>) { print OUT $line; }

You can read about FileIO in O'Reilly's Learning Perl. I highly recommend it.

-pete
"Pain heals. Chicks dig scars. Glory lasts forever."

Replies are listed 'Best First'.
Re: Re: Printing contents of file on a HTML page.
by Anonymous Monk on Sep 23, 2002 at 16:01 UTC
    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)
      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."
      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";