in reply to array does not accept more than one number

Assignments (as in "@product = ...;") replace the current contents of the variable to which data is being assigned. You need push here.

As an extra exercise, you should replace "foreach (@_) { if ($_ > $tot_avg) { ... } }" with a call to grep.

You should also look into separating I/O from computation. avg and above_avg shouldn't print anything.

Why are you using "&" in front of subroutine calls? That tells Perl to ignore the subroutine's prototype. Do you have a reason to do that?

Replies are listed 'Best First'.
Re^2: array does not accept more than one number
by Bloodnok (Vicar) on Dec 10, 2008 at 11:41 UTC
    Hi ikegami,

    I think your point about mixing computation & I/O may be a little unkind to the poster - methinx the OP contained the (admittedly primitive, but nonetheless effective) debug inserted whilst attempting to answer the question for themselves - shortly after which, they gave up and asked for help.

    That being said, ++ for the & hint - I didn't realise that - not that I use it anyway.

    A user level that continues to overstate my experience :-))