in reply to Doomsday algorithm

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);} }
This looks ugly to me, and it's not the programmer's task to repeat the same information multiple times.
@anchorday_week = qw(tuesday wednesday thursday friday saturday sunday + monday); my @tmp = splice @anchorday_week, 0, $year_anchor_day; push @anchorday_week, @tmp;
(see splice). Probably there are more elegant solutions, but at least it is shorter and won't warn you about given/when

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];

Replies are listed 'Best First'.
Re^2: Doomsday algorithm
by QM (Parson) on Sep 07, 2015 at 14:55 UTC
    To prove your point, when(5) duplicates "sunday".

    And you probably want something like:

    @anchor_day_week = qw(tuesday wednesday thursday friday saturday sunda +y monday) [$year_anchor_day+1..6,0..$year_anchor_day];

    ...though I dislike repeating $year_anchor_day. This just changes the repetition:

    push @anchor_day_week, splice @anchor_day_week, 0, $year_anchor_day;

    ...so a function to do this for you would be appropriate, even if it's only used once.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      Yes, that's what I meant with "more elegant solution". The next step would be to further "normalize" that $nbdays such that Sunday is the usual 0 or 7 (like in strftime %u or %w) by calculating
      my $nbdays = ($diff_to_doomsdates + $year_anchor_day + 2) % 7; # or -5
Re^2: Doomsday algorithm
by QuillMeantTen (Friar) on Sep 08, 2015 at 07:31 UTC

    Indeed indeed, its much more elegant to do it that way!