in reply to Re: help with algorithm
in thread help with algorithm
If I try 1 value for $test, like 4, it accurately returns Tuesday. However, if I use a complex value, like say 12, it returns Tuesday, Tuesday (where it should be Tuesday, Wednesday).#!/usr/bin/perl $test = 12; print "Days mask is $test.\n"; our %daycode = ( Sunday => 1, Monday => 2, Tuesday => 4, Wednesday => 8, Thursday => 16, Friday => 32, Saturday => 64, ); our %codeday; @codeday{ values(%daycode)} = keys %daycode; sub days { my $mask = shift || 127; sort { $daycode{$a} <=> $daycode{$b} } grep { $mask & $daycode{$_} } keys %daycode; } @newtest = days($test); foreach $num (@newtest) { print "$newtest[$num]\n"; }
Am I doing something wrong in interpreting this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: help with algorithm
by sauoq (Abbot) on Nov 17, 2002 at 01:44 UTC | |
|
Re: Re: Re: help with algorithm
by Zaxo (Archbishop) on Nov 17, 2002 at 01:37 UTC |