Dear Masters,
I have 5 functions (A,B,..E) which need to be called in various combinations, from user input. Currently I do it in the following hard coded way:
#!/usr/bin/perl -w my $func_com = $ARGV[0] || 'ABC'; #user input my @some_val = (0..10); my @all_res; # Now begin hard-coding all possible function call # with else-if if ($func_com eq 'A') { my @tempA = func_A(@some_val); push @all_res, [\@tempA]; } elsif ($func_com eq 'AB'){ my @tempA = func_A(@some_val); my @tempB = func_B(@some_val); push @all_res, [\@tempA, \@tempB]; } elsif ($func_com eq 'ABC'){ my @tempA = func_A(@some_val); my @tempB = func_B(@some_val); my @tempC = func_C(@some_val); push @all_res, [\@tempA, \@tempB, \@tempC]; } ##...etc, for all possible function combination of ## A,B, ...E # Do something with @all_res #------------------- # Functions collection #------------------- sub func_A { my @arr = @_; my @output; # do sth with @arr return @output; } sub func_B { my @arr = @_; my @output; # do sth with @arr return @output; } # .... etc until func_E
The problem I had is that: is there an alternative construct to avoid hard coding all the possible else-if function combinations above?
Because the functions will grow to more than just 5 above.

---
neversaint and everlastingly indebted.......

In reply to Howto avoid large hard-coded else-if function calls by neversaint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.