Perl's
.. operator can do magic increments, but only for strings in the format
/^[a-z]*[0-9]*$/i. But the problem you face here is that your increments must be by 1; not 1/100, not 5 minutes or 1 hour or whatever.
You'll have to somehow produce a range where increments are one, and scale them.
Plenty of people showed you how to do that with increments of 1/100, and here's a way to increment using time (in this exampel: increment in 5 minute intervals):
use POSIX qw(strftime);
use Time::Local;
my($from, $to, $incr) = ('13:00', '23:00', '0:05');
foreach($from, $to, $incr) {
if(/^(\d+):(\d\d)(?::(\d\d))?$/) {
$_ = ($1 * 60 + $2) * 60 + ($3 || 0);
}
}
@range = map { strftime "%H:%M:%S", gmtime $_ }
map $_*$incr, $from/$incr .. $to/$incr;
$_ = join " ", @range;
s/(.{1,70})(\s|$)/$1\n/g;
print ;
Output:
13:00:00 13:05:00 13:10:00 13:15:00 13:20:00 13:25:00 13:30:00
13:35:00 13:40:00 13:45:00 13:50:00 13:55:00 14:00:00 14:05:00
14:10:00 14:15:00 14:20:00 14:25:00 14:30:00 14:35:00 14:40:00
14:45:00 14:50:00 14:55:00 15:00:00 15:05:00 15:10:00 15:15:00
15:20:00 15:25:00 15:30:00 15:35:00 15:40:00 15:45:00 15:50:00
15:55:00 16:00:00 16:05:00 16:10:00 16:15:00 16:20:00 16:25:00
16:30:00 16:35:00 16:40:00 16:45:00 16:50:00 16:55:00 17:00:00
17:05:00 17:10:00 17:15:00 17:20:00 17:25:00 17:30:00 17:35:00
17:40:00 17:45:00 17:50:00 17:55:00 18:00:00 18:05:00 18:10:00
18:15:00 18:20:00 18:25:00 18:30:00 18:35:00 18:40:00 18:45:00
18:50:00 18:55:00 19:00:00 19:05:00 19:10:00 19:15:00 19:20:00
19:25:00 19:30:00 19:35:00 19:40:00 19:45:00 19:50:00 19:55:00
20:00:00 20:05:00 20:10:00 20:15:00 20:20:00 20:25:00 20:30:00
20:35:00 20:40:00 20:45:00 20:50:00 20:55:00 21:00:00 21:05:00
21:10:00 21:15:00 21:20:00 21:25:00 21:30:00 21:35:00 21:40:00
21:45:00 21:50:00 21:55:00 22:00:00 22:05:00 22:10:00 22:15:00
22:20:00 22:25:00 22:30:00 22:35:00 22:40:00 22:45:00 22:50:00
22:55:00 23:00:00
Tweaking the format spec for strftime you can produce a different time format.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.