This looks ugly to me, and it's not the programmer's task to repeat the same information multiple times.given ($year_anchor_day){ when(0){@anchorday_week = qw(tuesday wednesday thursday friday sat +urday sunday monday );} when(1){@anchorday_week = qw(wednesday thursday friday saturday su +nday monday tuesday);} when(2){@anchorday_week=qw(thursday friday saturday sunday monday +tuesday wednesday);} when(3){@anchorday_week=qw(friday saturday sunday monday tuesday w +ednesday thursday);} when(4){@anchorday_week=qw(saturday sunday monday tuesday wednesda +y thursday friday);} when(5){@anchorday_week=qw(sunday sunday monday tuesday wednesday +friday saturday);} when(6){@anchorday_week = qw(monday tuesday wednesday thursday fri +day saturday sunday);} }
(see splice). Probably there are more elegant solutions, but at least it is shorter and won't warn you about given/when …@anchorday_week = qw(tuesday wednesday thursday friday saturday sunday + monday); my @tmp = splice @anchorday_week, 0, $year_anchor_day; push @anchorday_week, @tmp;
Update: even simpler: drop that complete @anchorday_week, and then change the calculation of your $nbdays to
my $nbdays = ($diff_to_doomsdates + $year_anchor_day) % 7; return qw(tuesday wednesday thursday friday saturday sunday monday)[$n +bdays];
In reply to Re: Doomsday algorithm
by soonix
in thread Doomsday algorithm
by QuillMeantTen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |