Gossamer Forum
Home : Products : Links 2.0 : Customization :

Math with variables - how?

Quote Reply
Math with variables - how?
Hi again Smile.
I am attempting to do some calculations with variables. I'll bet this is a very simple task, I just don't know how to make it happen.
I have the following listed in my links.def file:
Code:
ReviewContent => [16, 'alpha', '40x3', 500, 0, '', ''],
ReviewContentRt => [17, 'numer', 10, 10, 1, 0, '^\d+$'],
ReviewNav => [18, 'alpha', '40x3', 500, 0, '', ''],
ReviewNavRt => [19, 'numer', 10, 10, 1, 0, '^\d+$'],
ReviewDesign => [20, 'alpha', '40x3', 500, 0, '', ''],
ReviewDesignRt => [21, 'numer', 10, 10, 1, 0, '^\d+$'],
This is a part of my review mod. The variables ReviewDesignRt, ReviewNavRt and ReviewContentRt contain the numerical rating from 1 to 10, while the other 3 variables contain the actual review text.
I wish to create an overall summary with the numerical variables. The math should look like this:

reviewsummary = ((ReviewDesignRt + ReviewNavRt + ReviewContentRt) / 3) * 10

My goal is to call this summary via a tag in my details page like this:

Review Summary: <%reviewsummary%>

If you would like to take a look at what I am working on, go here: http://genweb.net/...pages/Detailed/5.htm . Where you see the 0 behind "Overall Score", the summarized result should appear.

Thanks for you help guys, you are great!

Mike
Quote Reply
Re: Math with variables - how? In reply to
You didn't say where you're planning to install this routine and I've never worked with templates so this is just a guess, but I think it would have to be something like:

my $reviewsummary = (($in{'ReviewDesignRt'} + $in{'ReviewNavRt'} + $in{'ReviewContentRt'}) / 3) * 10

Be sure to watch for division by zero errors!

Dan O.
Quote Reply
Re: Math with variables - how? In reply to
i have just one question..

do you know perl? Smile

it seems like you do.. but for some reason i don't think you do..

obviously you are using templates.. so you have to first put this line into

sub site_html_detailed { inside the list of variables..

Code:
reviewsummary => $reviewsummary,

then in nph-build.cgi

sub build_detailed_view {

you would add something like this:

right under this:

Code:
$title_linked = &build_linked_title ("$rec{'Category'}/$rec{'Title'}");

put this:

Code:
$reviewsummary = (($rec{'ReviewDesignRt'} + $rec{'ReviewNavRt'} + $rec{'ReviewContentRt'}) / 3) * 10;

that should be all
Quote Reply
Re: Math with variables - how? In reply to
Jerry,
Thank you so much! You are right, I don't really know Perl, I am just beginning to learn it. I can modify simple things, like adding fields, etc... but I don't understand how to use variables yet, etc... as you can see.
I have the "Learning Perl" book by O'Reilly, but that one is not covering the more complex tasks of Perl. Is there perhaps another book that is recommendable for learning?

Thanx for saving my review mod!
Mike
Quote Reply
Re: Math with variables - how? In reply to
Can someone help me on this problem? I am stuck and need to get this resolved as soon as I can. Thanks Smile.
Quote Reply
Re: Math with variables - how? In reply to
hi..i haven't read a perl book yet.. but i use a book for reference.. it's ccalled

Programming Perl

by oreily Smile

it isn't a good book to read though.. hehe. .just reference..

but my dad says there is a book that he borrowed from his company library .. not sure what it's called.. but probably like Learning Perl in 21 days or something.. I think it's by Samsnet and it is green with a clam and a pearl on the front..

hope that helps
jerry
Quote Reply
Re: Math with variables - how? In reply to
As above, I am using the Code:
Code:
$reviewsummary = (($rec{'ReviewDesignRt'} + $rec{'ReviewNavRt'} + $rec{'ReviewContentRt'}) / 3) * 10;
Now under some circumstances, the value of $reviewsummary will have indinite decimals, for example 10/3=3.33333333333333.
How can I make sure that $reviewsummary is rounded to the nearest whole number, for example 3.33333333333 -> 3 or 6.6666666666 -> 7?
There must be a way Smile.

Thanks!
Mike
Quote Reply
Re: Math with variables - how? In reply to
change it to...

$reviewsummary = (int($rec{'ReviewDesignRt'} + $rec{'ReviewNavRt'} + $rec{'ReviewContentRt'}) / 3) * 10;
Quote Reply
Re: Math with variables - how? In reply to
Thanx again. Smile It worked, of course.

How is your review mod coming along?
Quote Reply
Re: Math with variables - how? In reply to
hehe..

review mod.. not yet.. i need to complete expired links.. which is practically done cept for a few little things that people want..

i will get to it this week though..

jerry