in reply to Re: [Homework Question] Subroutines & References
in thread [Homework Question] Subroutines & References
#!/usr/bin/perl use warnings; use List::Util qw(sum); my @list_of_numbers = (1 .. 50); my $i = (); my $a = (); sub mean { return sum(@_)/@_; } sub above_mean { $i == mean(@list_of_numbers); foreach (@list_of_numbers) { if ($a > $i) { print "$a is above mean, which is mean(@list_of_numbers)"; } } } print above_mean(@list_of_numbers);
This now returns:
Use of uninitialized value $a in numeric gt (>) at main.pl line 16.
However, I thought I declared $a earlier in my program?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: [Homework Question] Subroutines & References
by choroba (Cardinal) on Feb 11, 2015 at 16:33 UTC | |
by Hayest (Acolyte) on Feb 11, 2015 at 16:57 UTC | |
|
Re^3: [Homework Question] Subroutines & References
by AnomalousMonk (Archbishop) on Feb 11, 2015 at 17:21 UTC | |
by Anonymous Monk on Feb 11, 2015 at 18:57 UTC | |
by AnomalousMonk (Archbishop) on Feb 11, 2015 at 19:34 UTC | |
by Hayest (Acolyte) on Feb 11, 2015 at 19:48 UTC | |
by AnomalousMonk (Archbishop) on Feb 11, 2015 at 20:38 UTC |