Hi,

your mistake lies in how you call the sub getnumber.
$getnumber is a scalar value  and is not the same as getnumber() the sub,
so your program is assigning an undifined value to $x and $y

and i would like to advise you to use -w in all programs no matter how small 
they are. If you would run your program with 
 #!/usr/bin/perl -w
it will give warnings telling you the same as i told you know


Regards,

Stefaan

On Monday 04 June 2001 09:33, Carter and Cathleen wrote:

> > I'm real new to perl, but here's what I'm doing (The sub isn't working
> correctly).
>
> ########### BEGIN PROGRAM ############
>
> #!/usr/bin/perl
>
> $x = $getnumber;
>
> $y = $getnumber;
>
> $z = $x + $y;
>
> print "$x + $y = $z";
>
> sub getnumber {
>
>     print "Enter a number \n";
>     $number = <>;
>     chop($number);
>     $number
> }
>
> ############ END PROGRAM ##############
>
> Now when I spit this through I get:
>
> + = x
>
> I have yet to get a sub to work correctly.  Am I doing something
> drastically wrong? Thanks everyone!
>
> M. Carter Brown

Reply via email to