[prog] Re: Programming digest, Vol 1 #16 - Perl Question answered!

Malke Routh malke at attbi.com
Mon Sep 30 17:43:22 EST 2002


On Mon, 2002-09-30 at 13:26, programming-request at linuxchix.org wro
>> Message: 3
> Subject: Re: [prog] Little Perl Question
> From: Jenn Vesperman <jenn at anthill.echidna.id.au>
> Cc: "Programming at LinuxChix" <programming at linuxchix.org>
> Date: 30 Sep 2002 23:11:57 +1000
> 
> On Mon, 2002-09-30 at 22:55, Malke Routh wrote:
> 
> > how do I specify that the first number always has to be bigger than the
> > second number?
> 
> if ($first_number > $second_number) {
> 	$first_number - $second_number
> } else {
> 	print_error_message("error message goes here")
> }
> 
> Note that that is NOT in Perl syntax, you'll need to check your Perl
> book to determine how to use the if and how to print the error message.
> 
> But that should tell you how to do it.
> 
> 
> Jenn V.

> --__--__--
> 
> Message: 4
> Date: Mon, 30 Sep 2002 11:07:04 -0400
> From: Katie Bechtold <katie at katie-and-rob.org>
> To: "Programming at LinuxChix" <programming at linuxchix.org>
> Subject: Re: [prog] Little Perl Question
> 
> On Mon, Sep 30, 2002 at 05:55:46AM -0700, Malke Routh wrote:
> > $first_number - $second_number
> > how do I specify that the first number always has to be bigger than the
> > second number?
> 
> This is similar to Jenn's answer but based on a slightly different
> interpration of what you want to happen:
> 
> ($first_number, $second_number) = $a > $b ? ($a, $b) : ($b, $a);
> 
> This CONDITIONAL ? THEN : ELSE Perl syntax is a carry-over from C.
> My example assumes that $a and $b are your two randomly generated
> numbers.  The CONDITIONAL part tests whether $a > $b.  If that
> expression evaluates to true, $a is assigned to $first_number, and
> $b is assigned to $second_number.  If it evaluates to false, $b is
> assigned to $first_number and $a is assigned to $second_number.
> 
> -- 
> Katie Bechtold
> http://katie-and-rob.org/
> 
> 
> --__--__--
> 
> Message: 5
> Subject: RE: [prog] Little Perl Question
> From: Malke Routh <malke at attbi.com>
> To: Susan Peterson <susanpeterson at shaw.ca>
> Cc: "Programming at LinuxChix" <programming at linuxchix.org>
> Date: 30 Sep 2002 13:06:33 -0700
> 
> On Mon, 2002-09-30 at 06:40, Susan Peterson wrote:
> > Use a an if to test if the number1 > number2, does that make sense, 
> > and increment number1 inside the if statement. 
> > Susan
> > 

Thank you all.  With the hint from Susan (I got an email directly from
her early this morning), I was able to do it, but in a very clumsy way. 
Katie, you've shown me a way to do this much more cleanly.  Since I'm so
new at Perl, I'm sure that my code is a whole lot uglier than it should
be.  Right now, I'm just trying to get stuff to work and then I'll go
back and clean it up as I learn more.  Thanks again for the support. 
I've never programmed before, and it is *so* cool to write something and
have my computer do it!

Cheers,

Malke
-- 
Elephant Boy Computers
www.elephantboycomputers.com
"Don't Panic!"




More information about the Programming mailing list