L~R, thanks for the full framework! I was headed down the same path and manipulated the examples from the Panther to work with 24 hours per day:
#!/usr/bin/perl -w
use strict;
my %base_hours = ( sun => 0, mon => 24, tue => 48, wed => 72 , thu =>
+96, fri => 120, sat => 144 );
my $vector = interval_parse("Sat 9-17, Sun 9-17");
my $bits = unpack("b*", $vector);
print $bits, "\n";
sub interval_parse {
my ($interval_sequence) = @_;
my ($time_range) = "";
foreach my $day_hours (split /,/, $interval_sequence) {
my ($day, $from, $to) = ($day_hours =~ /([A-Za-z]+).*(\d+)-(\d+
+)/);
my $base = $base_hours{lc $day};
$from += $base;
$to += $base;
for (my $i = $from; $i < $to; $i++) {
vec($time_range, $i, 1) = 1;
}
}
return($time_range);
}
Thanks for the pointer!
-Nitrox
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.