Acme-Tools
view release on metacpan or search on metacpan
0.23 Jan 2019 Subs: logn, egrep, which. More UTF-8 "oriented" (lower, upper, ...)
Commands: zsize, finddup, due (improved), conv (improved, [MGT]?Wh
and many more units), due -M for stdin of filenames.
0.22 Feb 2018 Subs: subarr, sim, sim_perm, aoh2sql. command: resubst
0.21 Mar 2017 Improved nicenum() and its tests
0.20 Mar 2017 Subs: a2h cnttbl h2a log10 log2 nicenum rstddev sec_readable
throttle timems refa refaa refah refh refha refhh refs
eachr globr keysr popr pushr shiftr splicer unshiftr valuesr
Commands: 2bz2 2gz 2xz z2z
0.172 Dec 2015 Subs: curb openstr pwgen sleepms sleepnm srlz tms username
self_update install_acme_command_tools
Commands: conv due freq wipe xcat (see "Commands")
0.16 Feb 2015 bigr curb cpad isnum parta parth read_conf resolve_equation
roman2int trim. Improved: conv (numbers currency) range ("derivatives")
0.15 Nov 2014 Improved doc
t/10_md5sum.t
t/11_part.t
t/12_ht2t.t
t/13_random.t
t/14_brainfu.t
t/15_zip.t
t/16_fractional.t
t/17_roman.t
t/18_pad.t
t/19_serialize.t
t/20_range_globr.t
t/21_read_conf.t
t/22_trim.t
t/23_ed.t
t/24_db.t
t/25_pwgen.t
t/26_openstr.t
t/27_timestuff.t
t/28_wipe.t
t/29_cmd_z2z.t
t/30_cnttbl.t
ccn_ok
KID_ok
writefile
readfile
readdirectory
basename
dirname
wipe
username
range
globr
permutations
perm
permute
permute_continue
trigram
sliding
chunks
chars
cart
reduce
my @r;
my $test = $jump[0]>=0 ? sub{$x<$y} : sub{$x>$y};
while(&$test()){
push @r, $x;
$x+=$jump[0];
$jump[$_-1]+=$jump[$_] for 1..$#jump;
}
return @r;
}
=head2 globr
Works like and uses Perls builtin C<< glob() >> but adds support for ranges
with C<< {from..to} >> and C<< {from..to..step} >>. Like brace expansion in bash.
Examples:
my @arr = glob "X{a,b,c,d}Z"; # @arr now have four elements: XaZ XbZ XcZ XdZ
my @arr = globr "X{a,b,c,d}Z"; # same as above
my @arr = globr "X{a..d}Z"; # same as above
my @arr = globr "X{a..f..2}"; # step 2, returns array: Xa Xc Xe
my @arr = globr "{aa..bz..13}Z"; # aaZ anZ baZ bnZ
my @arr = globr "{1..12}b"; # 1b 2b 3b 4b 5b 6b 7b 8b 9b 10b 11b 12b
my @arr = globr "{01..11}b"; # 01b 02b 03b 04b 05b 06b 07b 08b 09b 10b 11b (keep leading zero)
my @arr = globr "{01..12..3}b"; # 01b 04b 07b 10b
=cut
sub globr($) {
my $p=shift;
$p=~s{
\{(-?\w+)\.\.(-?\w+)(\.\.(-?\d+))?\}
}{
my $i=0;
my @r=$1 le $2 ? ($1..$2) : reverse($2..$1);
@r=grep !($i++%$4),@r if $4;
"{" . join(",",@r) . "}"
}xeg;
glob $p;
}
=head2 permutations
How many ways (permutations) can six people be placed around a table:
One person: one way
Two persons: two ways (they can swap places)
Three persons: 6
Four persons: 24
0.23 Jan 2019 Subs: logn, egrep, which. More UTF-8 "oriented" (lower, upper, ...)
Commands: zsize, finddup, due (improved), conv (improved, [MGT]?Wh
and many more units), due -M for stdin of filenames.
0.22 Feb 2018 Subs: subarr, sim, sim_perm, aoh2sql. command: resubst
0.21 Mar 2017 Improved nicenum() and its tests
0.20 Mar 2017 Subs: a2h cnttbl h2a log10 log2 nicenum rstddev sec_readable
throttle timems refa refaa refah refh refha refhh refs
eachr globr keysr popr pushr shiftr splicer unshiftr valuesr
Commands: 2bz2 2gz 2xz z2z
0.172 Dec 2015 Subs: curb openstr pwgen sleepms sleepnm srlz tms username
self_update install_acme_command_tools
Commands: conv due freq wipe xcat (see "Commands")
0.16 Feb 2015 bigr curb cpad isnum parta parth read_conf resolve_equation
roman2int trim. Improved: conv (numbers currency) range ("derivatives")
0.15 Nov 2014 Improved doc
t/20_range_globr.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/20_range_globr.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 7+15;
ok_ref([range(11)], [0,1,2,3,4,5,6,7,8,9,10], 'range(11)' );
ok_ref([range(2,11)], [2,3,4,5,6,7,8,9,10], 'range(2,11)' );
ok_ref([range(11,2,-1)],[11,10,9,8,7,6,5,4,3], 'range(11,2,-1)' );
ok_ref([range(2,11,3)], [2,5,8], 'range(2,11,3)' );
ok_ref([range(11,2,-3)],[11,8,5], 'range(11,2,-3)' );
ok_ref([range(2,11,1,0.1)], [2, 3, 4.1, 5.3, 6.6, 8, 9.5 ],'range(2,11,1,0.1)');
ok_ref([range(2,11,1,0.1,-0.01)],[2, 3, 4.1, 5.29, 6.56, 7.9, 9.3, 10.75],'range(2,11,1,0.1,-0.01)');
sub ok_globr {
my($g,$e,$c)=@_;
my @g=globr($g);
$g=join" ",@g;
$e=join" ",@$e;
my $ok=$g eq $e && !defined$c || $c==@g;
ok( $ok, "globr $_[0] --> $e" );
print "got: $g\n" and
print "expected: $e\n" if not $ok;
}
ok_globr( "X{a,b,c}Y", [qw/XaY XbY XcY/] );
ok_globr( "X{a,b,c}Y", [glob("X{a,b,c}Y")] );
ok_globr( "X{a..c}Y", [glob("X{a,b,c}Y")] );
ok_globr( "X{a..c..2}Y", [glob("X{a,c}Y")] );
ok_globr( "{01..10}", [qw/01 02 03 04 05 06 07 08 09 10/] );
ok_globr( "{01..10..2}", [qw/01 03 05 07 09/] );
ok_globr( "{1..10}", [1..10] );
ok_globr( "{01..03..1}{00..99..5}", [grep/[05]$/,"0100".."0399"], 300/5 );
ok_globr( "XY{a..d..2}Z", [qw/XYaZ XYcZ/] );
ok_globr( "X{aa..bz..13}Z", [qw/XaaZ XanZ XbaZ XbnZ/] );
ok_globr( "X{bz..aa..13}Z", [qw/XbzZ XbmZ XazZ XamZ/] );
ok_globr( "X{10..02..3}.", [glob "X{10,07,04}."] );
ok_globr( "X{10..02..-3}.", [glob "X{10,07,04}."] );
ok_globr( "X{-10..-6}.", [glob "X{-10,-9,-8,-7,-6}."] );
ok_globr( "X{-10..-6..2}.", [glob "X{-10,-8,-6}."] );
#ok_globr( "X{-10..-06}.", [glob "X{-10,-07}."] ); #not ok yet
#deglob... #basisdatarapport-poengekv
#print join(" ",globr "*")."\n"; #hm
( run in 0.617 second using v1.01-cache-2.11-cpan-49f99fa48dc )