Computing.Net > Forums > Web Development > Perl help- adding variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Perl help- adding variables

Reply to Message Icon

Name: Davros
Date: March 14, 2004 at 08:13:50 Pacific
OS: -
CPU/Ram: -
Comment:

Hi,

I have a basic perl script that is for a pay per click advert. It stores users in a file and has basic password code to login and see what is owed.

The user, password, privalege (user / admin), pence per click and number of clicks so far is stored in a txt file.
This is part of the script:

open(FILE,"details.txt");
@raw = <FILE>;
close FILE;
$line=0;
foreach $line (@raw) {
chomp $line;
($user,$pass,$priv,$ppc,$nc) = split /:/,$line;

What I want to do is multiply $ppc and $nc together for each user and then add them all together set it as a variable to show the total of all users to be displayed in an admin account (so it's possible to see profit :D ).

How can I do this?

Many Thanks,
Davros



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: March 14, 2004 at 11:51:28 Pacific
Reply:

$total = 0;
open(FILE,"details.txt" or die $!);
while (<FILE>) {
   chomp;
   ($user,$pass,$priv,$ppc,$nc) = split /:/;
   $product = $ppc * $nc;
   $total += $prod;
}
close FILE;
print $total;


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Perl help- adding variables

Help! Deadline! - JavaScript var&td www.computing.net/answers/webdevel/help-deadline-javascript-varamptd/3219.html

Bad sites listing needed www.computing.net/answers/webdevel/bad-sites-listing-needed/197.html

help with Perl Mechanize www.computing.net/answers/webdevel/help-with-perl-mechanize/83.html