Chris Parker am Donnerstag, 30. November 2006 14:57:
> Adriano Ferreira wrote:
> >> STDIN and then make a loop for them. So you should remove the
> >> construction of @numbers from the loop, doing
> >
> > Code now is:
>
> print("Enter widths separated by spaces: \n");
> my @numbers = split /\s+/, <>;
> for my $width (@numbers) {
> my $result = &calculate($width);
> print("size = $width amount needed = $result \n");
> }
>
Hello Chris
> sub calculate {
> my $a = $_;
This does not what you think it does. You can see that by placing the
following "poor man's debug statement" after this line:
print "\$a=$a";
The solution's first step is to replace $a and $b by $x and $y (or whatever),
because $a and $b are special variables in perl, see perldoc -f sort.
Then, the line should be
my $x=shift;
or
my $x=$_[0];
Read perldoc perlsub for how arguments are passed to the sub.
There are other improvements and "do not"s in the code; your invited to get
your script do what it should and then reposting it :-)
Dani
> my $value = $a / 12;
> my $b = $value * $squareft;
> return $b;
> }
>
> Here is the results:
> Enter Total Square Footage: 1200
> Enter widths separated by spaces:
> 2 3 4
> Use of uninitialized value in division (/) at calc.pl line 23, <> line 2.
> size = 2 amount needed = 0
> Use of uninitialized value in division (/) at calc.pl line 23, <> line 2.
> size = 3 amount needed = 0
> Use of uninitialized value in division (/) at calc.pl line 23, <> line 2.
> size = 4 amount needed = 0
>
> It is pulling the size out nicely, but the value isnt making it into
> the sub?? I have tried my $a = $_[0] , a = @_, a = $width and am lost
> now.
>
> thanks again
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>