Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: "Junkyard" Puzzle: Average of Numbers

by DrZaius (Monk)
on May 13, 2001 at 12:22 UTC ( #80015=note: print w/ replies, xml ) Need Help??


in reply to "Junkyard" Puzzle: Average of Numbers

Here is my attempt:

sub avg { return eval '(' . join('+', @{$_[0]}) . ')/' . scalar(@{$_[0]}); }

Works pretty good over all :)


Comment on Re: "Junkyard" Puzzle: Average of Numbers
Download Code
Re: Re: "Junkyard" Puzzle: Average of Numbers
by $code or die (Deacon) on May 13, 2001 at 22:32 UTC
    Hi,

    You could make it shorter by taking out the scalar(). @{$_[0]} is already interpretted in scalar context.

    $code or die
    $ perldoc perldoc

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2015-07-06 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (69 votes), past polls