Perl Newby has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to convert the following to HTML. I have tried to run this and just can't seem to get it to work. Any suggestions?
open(DATA,"c:/MLB_boxscore.TXT") or die "Can't open file"; print "<html><head><title>My page</title></head><body>"; print "<table>"; $linescore = 0; if($linescore) { last if /^\s*$/; chomp; push @LS, split('\|',$_); print "<tr>"; } elsif(/^LINESCORE/) { $linescore = 1 } { print "<td>$linescore</td>"; print "</tr>"; } print "</table></body></html>"; close DATA;

Replies are listed 'Best First'.
Re: Printing a Text File
by lachoy (Parson) on Apr 11, 2001 at 02:13 UTC

    I don't know if I'm stating the obvious, but where's the part in your code where you actually read data from the file? That is, something like (assuming you rename DATA to MLB -- see below):

    while ( <MLB> ) { # do stuff with the line read in from the file here }

    As for the name DATA: it's a bad idea to use this name for a filehandle since this is used to denote data that can be embedded in the script file -- see perldoc Selfloader for more info.

    Chris
    M-x auto-bs-mode

Re: Printing a Text File
by ton (Friar) on Apr 11, 2001 at 02:13 UTC
    Two things:
    1. Don't open to the DATA filehandle; this is a reserved filehandle name in Perl. Open to INPUT instead (for example).
    2. You might want to try reading from the filehandle... :)

    -----

    Be bloody, bold, and resolute; laugh to scorn
    The power of man...

Re: Printing a Text File
by voyager (Friar) on Apr 11, 2001 at 02:24 UTC
    In addition to above, you don't show that you have supplied http headers. Simplest way is:
    use CGI; my $q = CGI::new; print $q->header; # and $q->start_html and *many* more
      Actually, simplest is:
      use CGI qw (:standard); print header;
      There's (usually) no need to use the OO interface in CGI.pm... the functional interface is, well, a lot more functional. :-D

      Gary Blackburn
      Trained Killer