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

<html> <body>

Hi,

I am having a problem figuring out how to multiply two numbers I get from a query and then dividing it by another number and subtracting one.

Let me show you what it would look like. It would look something like this ((data1*data2)/data3)-1). Is it possible to do this type of thing?

I've tried breaking it up by doing this
my $question = (data1*data2);
my $question2 = (($question/data3)-1);

And that doesn't seem to work. I keep getting the error on the line with the multiplication sign. Could it be that * is used for something else in perl?

I would be greatful.for any help

Thanks

here's my code

</body> </html>
sub main { my $oCGI = CGI->new(); my $oSearch = XDrive::DatabaseO::Search->new(undef); my $oDBO = XDrive::DatabaseO->new(); my $dbh = $oDBO->fetchDBH(); my (sql, results,avg_additional,$new_user,avg_repeat_logins ) +; ########################### # # Queries # ########################### $sql = "SELECT count(login_num) FROM disk_account WHERE login_num >= 1 AND last_login >= sysdate - 30 AND created_on >= sysdate - 30"; $result = $oSearch->XDSQLSearch($sql); my $life_one = $result->[0]->[0]; $sql = "SELECT count(*) FROM disk_account WHERE last_login >= SYSDATE - 30 AND created_on >= sysdate - 30"; $result = $oSearch->XDSQLSearch($sql); my $life_two = $result->[0]->[0]; $new_users = ($life_one/$life_two); $sql = "SELECT avg(login_num) FROM disk_account WHERE last_login >= sysdate - 30 AND created_on >= sysdate - 30"; $result = $oSearch->XDSQLSearch($sql); $avg_repeat_logins = $result->[0]->[0]; $avg_additional = (($avg_repeat_logins*life_two)/life_one)-1); $oSearch->disconnect(); $dbh->disconnect(); $oDBO->disconnect(); $oSearch->disconnect(); }

Replies are listed 'Best First'.
Re: Need help in doing multiplication
by btrott (Parson) on Aug 03, 2000 at 05:59 UTC
    That line is causing an error because you don't have a $ in front of the variable. It should be:
    $avg_additional = $avg_repeat_logins * $life_two / $life_one - 1;
    Notice that you can take out all of the parentheses in your statement.
Buzzcutbuddha: (* Makes Globs Of Bare Words)-RE: Need help in doing multiplication
by buzzcutbuddha (Chaplain) on Aug 03, 2000 at 15:28 UTC
    The splat, or asterix is used on bare words to make globs (best to read the manual on that, my understanding is still hazy on globs and would best confuse you more than help you) and like Btrott pointed out you are missing your '$' on one of your vars.

    From the looks of your code, you don't have any space between the vars and the operator, and therefore, Perl isn't quite sure what you are trying to do.

    Add your $ and separate your vars and operators for readability. Cheers!
Re: Need help in doing multiplication
by fgcr (Novice) on Aug 05, 2000 at 03:39 UTC
    <html> <body>

    Of course. How could I have missed that. Thanks so much for your help. I start triple checking things now.

    Fio