http://qs321.pair.com?node_id=81816

ryan has asked for the wisdom of the Perl Monks concerning the following question:

I needed to get a list of strings representing time between two given PM times in specific intervals. So between 7pm and 8:20pm inclusive in 20 minute intervals you get: 7:00 7:20 7:40 8:00 8:20

I didn't use any Time libs becuase I found them slow for repetitive parsing plus i wanted to nut it out myself.

Just wondering what other ways people may go about this task while keeping the code fairly readable and not overly nested?

#!/usr/bin/perl $t1 = '7:30'; #minimum time $t2 = '11:45'; #maximum time @t1 = split(':', $t1); @t2 = split(':', $t2); $interval = 15; #may be (10,15,20,30) #create an array of intervals for (0..(60/$interval)-1) { $mins[@mins]=(($_*$interval) ? $_*$interval : '00'); } #loop for number of hours requested for ($t1[0]..$t2[0]) { #loop for number of intervals in array foreach $mins (@mins) { #print if min <= result <= max if ($_<=$t2[0]&&$mins<=$t2[1]) { print "$_:$mins\n" if (!($_==$t1[0]&&$mins<$t1[1])) } } }