Suggestions are suggestions: you cherry pick them according to your needs and tastes. :) However ... where is your science? Simply "feeling" that these default values will not work for is not the same as actually testing them out.

use strict; use warnings; use Test::More qw( no_plan ); use DateTime; for my $min (1 .. 20) { for my $max (30 .. 80) { for my $inc ( 0 .. 1 ) { is_deeply [ jeffa( $min, $max, $inc ) ], [ over2sd( $min, $max, $inc ) ], ; } } } done_testing(); sub jeffa { my $min = shift || 0; my $max = shift || 0; my $inclusive = $_[0] ? 1 : 0; my ($xs,$ns) = (DateTime->now,DateTime->now); $xs->subtract(years => $min, days => -$inclusive); $ns->subtract(years => $max, days => 364 + $inclusive); return $xs->ymd('-'),$ns->ymd('-'); } sub over2sd { my ($agemin,$agemax,$inclusive) = @_; die "Minimum age omitted in DoBrangefromAges" unless (defined $age +min and $agemin ne ''); $agemin = int($agemin); $agemax = int($agemin) unless defined $agemax; $agemax = int($agemax); $inclusive = ($inclusive ? $inclusive : 0); my ($maxdob,$mindob) = (DateTime->now,DateTime->now); $maxdob->subtract(years => $agemin, days => -$inclusive); $mindob->subtract(years => $agemax, days => 364 + $inclusive); return $maxdob->ymd('-'),$mindob->ymd('-'); }

When i run this test i see no difference in the output of your code and mine. It is certainly possible that i have not tested as fully as can be tested, but i have more certainty that i what i provided will give you the desired output, as was my goal.

UPDATE:
You only need change one line in my sub. From this:

my $max = shift || 0;
to this:
my $max = shift || $min;
Returning 0 if the user passes 0 arguments seems like justice to me. >:)

use Test::More qw( no_plan ); is_deeply [ jeffa( ) ], [ over2sd( ) ], ; is_deeply [ jeffa( 10 ) ], [ over2sd( 10 ) ], ; __END__ Use of uninitialized value $agemin in int at foo.pl line 37. ok 1 ok 2 1..2

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re^3: Get DoB Bounds from Age Range by jeffa
in thread Get DoB Bounds from Age Range by over2sd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.