Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: Re: Re: Re: Unix Perl and Html

by thatguy (Parson)
on Aug 22, 2001 at 20:14 UTC ( #107014=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Unix Perl and Html
in thread Unix Perl and Html

that's close. The filehandle is a reference to the file, so instead of having the path to the file, it needs to be a keyword or decriptive word. Then inside the quotes you need to put the filename (with path).

Here's what it should look like:

#!/usr/bin/perl -w use strict; use CGI; # start new cgi process my $main=new CGI; # print html headers print $main->header; # print html tags and add title print $main->start_html ("Printer Status"); # open /usr/lsys/printstatus/printstatus.out under filehandle LOGFIL +E open(LOGFILE," /usr/lsys/printstatus/printstatus.out"); # while there is data in LOGFILE while(<LOGFILE>) { # remove newlines (\n) from input chomp; # if the imput is not the divider line if (! ($_=~/----------------------------/)) { # put the contents of the current line into the array @status # we are spliting on the space so that every word seperated by # a space becomes a new element in the array my @status = split(/ /, $_); # if the first element of @status does not equal 'name' (the t +itle header if (($status[0] eq "name") && ($status[1] eq "display")) { # print the start of the table print "<center><table width=250 border=1><tr align=center> +\n"; # for each element in @status for (@status) { # print a new table cell print "<td><b>$_</b></td>\n"; } # close the table row print "</tr>\n"; } } } # close the table print "</table>\n"; # close LOGFILE close (LOGFILE); exit;
if you are curious about some of the commands/functions that are used, type perlfunc:NameOfFunction in the super search.
-p


Comment on Re: Re: Re: Re: Re: Unix Perl and Html
Select or Download Code
Re: Re: Re: Re: Re: Re: Unix Perl and Html
by meccaxlr (Initiate) on Aug 27, 2001 at 18:33 UTC
    Thanks alot once again! Do you have any advice on setting up an array, I have to take input from 3 different files and put them into a nice array. Any suggestions? Is it difficult .
      something like this will read in all the files listed in @files. It also cuts down on repetitive code and allows scalability.

      my @files= qw| /path/to/file1 /path/to/file2 /path/to/file3 |; my @allfiles; for my $filename(@files){ open(FILE," $filename") || die "Cannot open $filename: $!\n"; while(<FILE>) { push @allfiles, $_; } close(FILE); }

      -p
        Better would be:
        my @files= qw| /path/to/file1 /path/to/file2 /path/to/file3 |; my @allfiles; for my $filename(@files){ open FILE, $filename || die "Cannot open $filename for reading: $!\n"; push @allfiles, $_ while (<FILE>); close FILE; } # Or (and even more Perlish) ... my @files= qw| /path/to/file1 /path/to/file2 /path/to/file3 |; my @allfiles; for my $filename(@files){ open FILE, $filename || die "Cannot open $filename for reading: $!\n"; push @allfiles, <FILE>; close FILE; }

        ------
        /me wants to be the brightest bulb in the chandelier!

        Vote paco for President!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://107014]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-09-20 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (153 votes), past polls