in reply to Ordering Template cards

G'day Bod,

"But I especially do not like the conditional subroutine calls with magic numbers in the statement modifiers."

As far as the magic numbers are concerned, you can associate them with meaningful names; however, I really wanted to comment on the "conditional subroutine calls". Consider using a despatch table. Here's a rough example.

my %handler_for = ( card1name => \&card_call_center, card2name => \&card_price_data, ... ); ... while (my $card = ...) { $handler_for{$card}->(); }

— Ken

Replies are listed 'Best First'.
Re^2: Ordering Template cards
by Bod (Parson) on Jan 25, 2021 at 20:50 UTC
    Consider using a despatch table

    Fabulous - thanks Ken and ++

    That's exactly the kind of "more elegant solution" I was looking for. It is clearer, more extensible and much nicer than my solution.