CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Post deleted by vahidperl

 



vahidperl
New User

Sep 21, 2012, 1:04 AM

Post #1 of 5 (2133 views)
Post deleted by vahidperl

 


BillKSmith
Veteran

Sep 21, 2012, 5:10 AM

Post #2 of 5 (2120 views)
Re: [vahidperl] Seach a list [In reply to] Can't Post

I assume that the second term (-2.01/31) in your example is wrong. Should be (-2.01/12).

Use an array of hashes.

Code
use strict; 
use warnings;
my @dat = (
{score => [-4.3, 24], range => [ 96, 205] },
{score => [-2.01, 12], range => [145, 210] },
{score => [ 3, 31], range => [180, 240] },
{score => [ 7, 14], range => [200, 250] },
);
my $num = $ARGV[0];

my $output;
my $count;

foreach (@dat) {
if ($num >= $_->{range}[0] and $num <= $_->{range}[1]) {
$output += ($_->{score}[0] / $_->{score}[1]);
$count++;
}
}

die "Number does not match any score\n" if !defined $count;
$output /= $count;
print "$num $output\n";

Good Luck,
Bill


vahidperl
New User

Sep 21, 2012, 1:30 PM

Post #3 of 5 (2086 views)
Post deleted by vahidperl [In reply to]

 


BillKSmith
Veteran

Sep 21, 2012, 2:04 PM

Post #4 of 5 (2081 views)
Re: [vahidperl] Seach a list [In reply to] Can't Post

We are here to help you, not to do your work! I have shown you a reasonable data structure. Try to read data from a file into it. Show us what you have done, and we will give you hints on how to fix it.
Good Luck,
Bill


Laurent_R
Veteran / Moderator

Sep 23, 2012, 8:40 PM

Post #5 of 5 (2045 views)
Re: [BillKSmith] Seach a list [In reply to] Can't Post

Yep, I'd be happy to help, but if the original poster removes his or her post, so that we don't know what the problem is, then I can't help much.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives