Thank you all for you prompt and accurate help. I will not soon forget the
difference between assigning a value and a numeric comparison operator.
Jason, with the "@a=$number" statement, I was trying to create the list by
changing contexts. In other words, if returns the input in a scaler
cont
On Jan 31, Rambog said:
>I am attempting a program that reads a list of numbers from the screen until
>the number 999 is read. It then prints the sum of all numbers read- with
>the exception of the 999.
>
>My code looks like:
>
>until ($number=999) {
You want ==, not = here.
>print "Please inp
Change
until ($number=999) {
and
if ($number=999) {
to == 999. You are assigning the value 999 to the $number var in both cases,
not checking if it is equal to 999.
Simple mistake, we've all made it ;)
HTH
John
P.S Here is how I would code this script.
use strict;
my ($number, $total);
You are using the assignment operator in your "until" and "if" blocks, and
*not* the comparison operator. You need to use the double equals for what
you want...
until ($number == 999)
And
if ($number == 999)
Rob
-Original Message-
From: Rambog [mailto:[EMAIL PROTECTED]]
Sent: Thursd
At 11:09 AM 1/31/2002 -0500, you wrote:
>I am attempting a program that reads a list of numbers from the screen until
>the number 999 is read. It then prints the sum of all numbers read- with
>the exception of the 999.
>
>My code looks like:
>
>until ($number=999) {
>print "Please input your numb
A couple of things here ...
1) Watch out for = vs. == ... very tricky! Your first until loop won't even
eval b/c $number=999 is always true.
2) @a=$number; is not what you want... I'm not even sure what that does. You
probably want to use the push function, like so:
push @a, $number