On Tue, Nov 04, 2003 at 07:54:54PM +0900, Alex wrote:
> I have a bit string , 7 bits, every bit representing a day of the week.
> e.g. 1110011.
> Is there and easy way where I can translate/format that string in a query.
> I want to give the string back with a '-' for every 0 and the first char
> of the Day for every '1'.
> example 1100111 = SM--TFS.
A simple perl function:
sub mybits {
my $bits = shift;
my $ret = "";
foreach my $i (0 .. 6) {
substr($ret, $i, 1,
(substr($bits, $i, 1) =~ /1/ ?
(qw(S M T W T F S))[$i] : "-"));
}
return $ret;
}
$ ./test.pl 1001011
S--W-FS
You can of course use it with plperl.
--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
Hi! I'm a .signature virus!
cp me into your .signature file to help me spread!