in reply to Expanding dates

OTTOMH, assuming that your input is "X Y" where that is the range..
<INPUT>; /^(\d*)\s*(\d*)/; #split input ($first, $second) = ($1, $2); $first =~ /(\d{4})(\d{2})?(\d{2})?/; # split the year, mo, and day $fyear = $1; $fmon = defined( $2 ) ? $2 : 1; #if not specified, use 1 $fday = defined( $3 ) ? $3 : 1; #ditto $second =~ /(\d{4})(\d{2})?(\d{2})?/; # split the year, mo, and day $syear = $1; $smon = defined( $2 ) ? $2 : 1; #if not specified, use 1 $sday = defined( $3 ) ? $3 : 1; #ditto # got input, now to 'expand' my @list; for ( my $y = $fyear; $y <= $syear; $y++ ) { for ( my $m = ( $y==$fyear ) ? $fmon; 1 ; $m <= ( $y==$syear) ? $smon : 12; $m++ ) { for( my $d = ( ( $y==$fyear) && ($m==$fmon) ) ? $fday : 1 ; $d <= ( ( $y==$syear) && ($m==$smon) ) ? $sday : 31 ; $d++) { push @list, sprintf("%04d%02d%02d", $y, $m, $d); } } } # And now @list holds an expanded list between the first # date and second, including 'fake' days that probably can # be ignored... maybe include here a test to remove the # bogus entires: my @goodlist; foreach $i @list { if ( -x $i ) { push @goodlist, $i; } } # note that @list or @goodlist will be already sorted in # date order...

Edit: 2001-03-03 by neshura

Replies are listed 'Best First'.
Re: Re: Expanding dates
by lemming (Priest) on Feb 13, 2001 at 01:00 UTC
    While it looks like this will work, it will take a lot longer than Corion's. Also, you should use < code> tags instead of < pre> tags
    It would be faster to do a readdir and weed out the files outside the range. Doing a file test for every possibilty can be a bit disk intensive. Crossing the century boundry isn't much of a problem since the file range format is done so that the file for Dec 20, 1999 is less than Jan 4, 2001. You method does make sure that non-dates are not listed.
    I was wondering if this question could be a homework question, which stops me from doing a full solution. (well, that and I should be working...)