Statis...:Median(3pm)
β¨ Statistics::Basic::Median β¨
okay bestie, gather round π this is the Statistics::Basic::Median page from the Statis...:Median(3pm) manual (yes it's a perl thing, section 3pm, user contributed perl documentation, we love that for us). It's the module that finds the median of a list. that's it. that's the whole vibe. slay.
πΈ NAME πΈ
Statistics::Basic::Median β find the median of a list π
π¦ SYNOPSIS π¦
okay so you invoke it like this, super simple:
my $median = median(1,2,3);
or, if you already got a vector lying around, like this:
my $v1 = vector(1,2,3);
my $med = median($v1);
and then bestie you can either query the values or just print them, whichever, no pressure:
print "The median of $v1: $med\n";
my $mq = $med->query;
my $m0 = 0+$med;
π notice that $m0 = 0+$med line? that's the numeric context flex, we'll get to it in OVERLOADS, iykyk.
want a 20 point "moving" median? iconic. do it like so:
use Statistics::Basic qw(:all nofill);
my $sth = $dbh->prepare("select col1 from data where something");
my $len = 20;
my $med = median()->set_size($len);
$sth->execute or die $dbh->errstr;
$sth->bind_columns( my $val ) or die $dbh->errstr;
while( $sth->fetch ) {
$med->insert( $val );
if( defined( $m = $med->query ) ) {
print "Median: $m\n";
}
# This would also work:
# print "Median: $med\n" if $med->query_filled;
}
that nofill up there in the use line is doing WORK, she's the reason query can come back undefined until the buffer is actually full. main character behavior fr fr. π
π METHODS π
new()β the constructor. she takes a single array ref or a singleStatistics::Basic::Vectoras arguments, and hands you back aStatistics::Basic::Medianobject. π«Ά
β οΈ note: normally you'd just use themedian()constructor instead of building these by hand withnew(). like, why would you. but you can.
_OVB::import()β this module also inherits all the overloads and methods fromStatistics::Basic::_OneVectorBase. so everything that base class can do, this one can do too. inherited the whole wardrobe. π
π OVERLOADS π
this object is overloaded, meaning she's flexible like that. in string context she tries to return an appropriate string for the calculation, and in numeric context she gives you the value of the computation.
and in boolean context? bestie. this object is always true β even when it's empty. π so do NOT go trusting a truthy check to tell you if there's data in there. it's giving confident-but-empty. check with query_filled or defined instead, ok? π
π AUTHOR π
Paul Miller <jettero@cpan.org> β the legend, the icon, the moment. π
β COPYRIGHT β
Copyright 2012 Paul Miller -- Licensed under the LGPL
(so like, keep the license, respect the license, periodt. π )
π SEE ALSO π
perl(1)Statistics::BasicStatistics::Basic::_OneVectorBaseStatistics::Basic::Vector
okay that's the whole page, you ate that π go forth and find some medians. this was perl v5.36.0, dated 2022-11-19, and it's still serving looks. mwah πβ¨π
π¦ where this page comes from
- debian bookworm: libstatistics-basic-perl 1.6611-3 Β· LGPL-2.1-only
- debian trixie: libstatistics-basic-perl 1.6611-3 Β· LGPL-2.1-only
- ubuntu noble: libstatistics-basic-perl 1.6611-3 Β· LGPL-2.1-only
- ubuntu resolute: libstatistics-basic-perl 1.6611-3 Β· LGPL-2.1-only
- ubuntu stonking: libstatistics-basic-perl 1.6611-3 Β· LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms