| 1 | package Array::Sample::Partition; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use 5.010001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 2 | ▶ | use Exporter qw(import); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||
| 10 | 2 | our $DATE = '2022-05-20'; # DATE | |||||||||||
| 11 | 2 | our $DIST = 'Array-Sample-Partition'; # DIST | |||||||||||
| 12 | 2 | our $VERSION = '0.003'; # VERSION | |||||||||||
| 13 | |||||||||||||
| 14 | 2 | our @EXPORT_OK = qw(sample_partition); | |||||||||||
| 15 | |||||||||||||
| 16 | 14 | ▶ | sub sample_partition { | ||||||||||
|
Subroutine
sample_partition: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||
| 17 | 14 | my ($ary, $n, $opts) = @_; | |||||||||||
| 18 | 14 | ▶ | $opts //= {}; | ||||||||||
|
Condition100%2/2
$opts //= {}
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
| |||||||||||||
| 19 | |||||||||||||
| 20 | 14 | ▶ | $n = @$ary if $n > @$ary; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | |||||||||||||
| 22 | 14 | my @res; | |||||||||||
| 23 | 14 | for my $i (1..$n) { | |||||||||||
| 24 | 19 | my $idx = int($i*@$ary/($n+1)); | |||||||||||
| 25 | 19 | ▶ | push @res, $opts->{pos} ? $idx : $ary->[$idx]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | } | ||||||||||||
| 27 | |||||||||||||
| 28 | 14 | @res; | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | 2 | 1; | |||||||||||
| 32 | # ABSTRACT: Sample elements from an array by equal partitions | ||||||||||||
| 33 | |||||||||||||
| 34 | __END__ | ||||||||||||