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:
How can I do it ??

 



airo
stranger

Apr 11, 2001, 10:24 PM

Post #1 of 4 (488 views)
How can I do it ?? Can't Post

How would this be done?
# needs to cover all numbers(5.01,5.05,8.99...)between the two limits
if($t >= 5.00 BUT <=9.00) {
$total = $t * 10;
}else{
$total = 0;
}
print $total

thanks
paul


Jean
User


Apr 11, 2001, 11:56 PM

Post #2 of 4 (485 views)
Re: How can I do it ?? [In reply to] Can't Post

You can use logical AND (&&) and logical OR (or) in order to define relations between several expressions,
i.e.
Exp1 && Exp2 will return true only if BOTH expressions are TRUE.
Exp1 or Exp2 will return true if at least ONE expression is TRUE (both true returns true also).

Here is what you need:

Code
if( ($t >= 5) && ($t <= 9) ) { 
}

Jean Spector
QA Engineer @ Extent Technologies, Ltd.
mage@lycosmail.com


freddo
User

Apr 12, 2001, 12:02 AM

Post #3 of 4 (485 views)
Re: How can I do it ?? [In reply to] Can't Post

Hello airo,

here's how to do:

Code
if ($t >=5 && $t<=9) {  
$total=$t*10
} else {
$total=0;
}

you may probably want to check the perldoc perlop man page about C-Style Logical AND (&&).
And like there's more than one way to do it:

Code
$total = ( $t>=5 && $t<=9 ) ? $t*10 : 0;

(still on the perldoc perlop but about Conditional Operator (?))

i hope this helps
freddo


; -----
Real Programmers dont need class,
They just have style...


airo
stranger

Apr 12, 2001, 8:30 AM

Post #4 of 4 (476 views)
Re: How can I do it ?? [In reply to] Can't Post

Thanks so much
paul

 
 


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

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