Acme-Tools
view release on metacpan or search on metacpan
Returns: Something I<true> if the first argument is numerically between the two next. Uses Perls C<< < >>, C<< >= >> and C<< <= >> operators.
=head2 btw
Like L<between> but instead of assuming numbers it checks all three input args
and does alphanumerical comparisons (with Perl operators C<lt>, C<ge> and C<le>) if any of the
three input args don't look like a number or look like a number but with
one or more leading zeros.
btw(1,1,10) #true numeric order since all three looks like number according to =~$Re_isnum
btw(1,'02',13) #true leading zero in '02' leads to alphabetical order
btw(10, 012,10) #true leading zero here means oct number, 012 = 10 (8*1+2), so 10 is btw 10 and 10
btw('003', '02', '09') #false because '003' lt '02'
btw('a', 'b', 'c') #false because 'a' lt 'b'
btw('a', 'B', 'c') #true because upper case letters comes before lower case ones in the "ascii alphabet"
btw('a', 'c', 'B') #true, btw() and between switches from and to if the first is > the second
btw( -1, -2, 1) #true
btw( -1, -2, 0) #true
Both between and btw returns C<undef> if any of the three input args are C<undef> (not defined).
t/02_general.t view on Meta::CPAN
ok( between(7, 1,10) ,'between a');
ok( between(undef, 1,10) eq '' ,'between b');
ok( between(7, 10,1) ,'between c');
ok( between(5,5,5) ,'between d');
#--btw, a better(?) between
ok( btw(7, 1,10) ,'btw a');
ok( btw(undef, 1,10) eq '' ,'btw b');
ok( btw(7, 10,1) ,'btw c');
ok( btw(5,5,5) ,'btw d');
ok( btw(1,1,10) ,'btw e'); # numeric order since all three looks like number according to =~$Re_isnum
ok( btw(1,'02',13) ,'btw f'); # leading zero in '02' leads to alphabetical order
ok( btw(10, 012,10) ,'btw h'); # leading zero here means oct number, 012 = 10 (8*1+2), so 10 is btw 10 and 10
ok(!btw('003', '02', '09') ,'btw i'); #
ok(!btw('a', 'b', 'c') ,'btw j'); #
ok( btw('a', 'B', 'c') ,'btw k'); #
ok( btw('a', 'c', 'B') ,'btw l'); #
ok( btw( -1, -2, 1) ,'btw m');
ok( btw( -1, -2, 0) ,'btw n');
ok( btw( -1, -2, '0e0') ,'btw o');
#my($btw,$btw2)=(0,0);
( run in 0.600 second using v1.01-cache-2.11-cpan-64827b87656 )