Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^2: Calculating statistical median

by jimbojones (Friar)
on Jul 13, 2005 at 15:35 UTC ( #474589=note: print w/ replies, xml ) Need Help??

in reply to Re: Calculating statistical median
in thread Calculating statistical median


Is there a special reason for the array reference? Versus this?
sub mean { my $result; foreach (@_) { $result += $_ } return $result / @_; } my @points = qw(1 2 3 4); print mean @points;

Comment on Re^2: Calculating statistical median
Download Code
Replies are listed 'Best First'.
Re^3: Calculating statistical median
by dirac (Beadle) on Jul 14, 2005 at 07:07 UTC
    Copying an array or hash into @_ takes time. Passing arrays and hashes by reference is straightforward.
    See Benchmark
    If you want median:
    sub median { $_[0]->[ @{$_[0]} / 2 ] } my @points = 0..100; print median(\@points), "\n";

      Thanks. Didn't know about the speed issue.

      - j

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2015-07-30 01:54 GMT
Find Nodes?
    Voting Booth?

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

    Results (269 votes), past polls