Adam,

You could add a line to your script that adds the extracted number to a variable
(like $total).
Just add:

...
$inline = <infile>;
chomp $inline;
@line = split (" " , $inline);
$total += $line[0] unless($line[0] =~ m/[^\d]/); #added
print <<"EOF";
...

You can omit the unless statement if you are positive $line[0] will always
contain a number here.
Then, print $total outside of your while loop.

...
  </table>

EOF
}
print <<"EOF";
<html stuff>$total<html stuff>
</body>
...

Hope this helps.

Ben Huyck


-----Original Message-----
From: Adam Mc Gregor [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 24, 2001 10:24 AM
To: [EMAIL PROTECTED]
Subject: counting in CGI - any pointers?


Hi all
I have a text file that I am displaying in an html table on a website.
this text file has on line of data, set out like this:

foo
3
bleeb
45
blee
56
stuff
67

what i need to do is get it to total all the numbers in this file once
it has finished outputting the data to my table and display that total
somewhere on the page

the script i am using to output the data:

#!/usr/bin/perl
print "Content-type: text/html\n\n";

open infile, "</www/webs/affinityinternet.co.za/stats/webusage/libweb";
print <<"EOF";

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Web Site URL</title>
</head>

<body>


EOF
while (eof(infile) ne 1) {
$inline = <infile>;
chomp $inline;
@line = split (" " , $inline);
print <<"EOF";
<div align="center">
  <center>
  <table bgcolor="#787CA8" bordercolorlight="#98CCFF"
bordercolordark="#98CCFF" border="1" width="500" >
<tr>
      <td bordercolorlight="#98CCFF" bordercolordark="#98CCFF"
style="text-align: Center" width="500" >
        <p align="centre"><b><font
face="Arial">http://members.freemail.absa.co.za/$line[0]</font></b></td>

EOF
$inline = <infile>;
chomp $inline;
@line = split (" " , $inline);
print <<"EOF";

        <tr>
      <td bordercolorlight="#98CCFF" bordercolordark="#98CCFF"
style="text-align: Center" width="500" >
        <p align="centre"><b><font
face="Arial">$line[0]kb</font></b></td>
      
  </table>

EOF
}
print <<"EOF";
</body>

</html>
EOF
The information in this e-mail, and any attachment therein, is confidential and
for 
use by the addressee only. If you are not the intended recipient, please return
the 
e-mail  to the sender and delete it from your computer. Although Affinity
Internet 
attempts to sweep e-mail and attachments for viruses, it does not guarantee that

either are  virus-free and accepts no liability for any damage sustained as a
result
of viruses.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to