Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: [Homework Question] Subroutines & References

by toolic (Bishop)
on Feb 11, 2015 at 16:24 UTC ( [id://1116348]=note: print w/replies, xml ) Need Help??


in reply to [Homework Question] Subroutines & References

perltidy can help make this type of error more obvious by auto-indenting your code:
#!/usr/bin/perl use strict; 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);

Replies are listed 'Best First'.
Re^2: [Homework Question] Subroutines & References
by Hayest (Acolyte) on Feb 11, 2015 at 16:30 UTC
    Thanks for the suggestion, I could use that (big time). It still doesn't execute with the correct bracket location, however. Looking into it now... I'm a complete beginner with programming, and Perl. This community has been nothing but helpful to me. Thanks again!

      "Correct bracket location" doesn't enter into it.

      The hint is that your final print statement is deeply indented after tidying. It is indented to the same level as the if statement, because that's where it goes based on the brackets you wrote.

      You didn't want it to be at the same level as the if statement, and that's the clue that you need to add the close brackets.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1116348]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found