neversaint has asked for the wisdom of the Perl Monks concerning the following question:
The problem I had is that: is there an alternative construct to avoid hard coding all the possible else-if function combinations above?#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Howto avoid large hard-coded else-if function calls
by BrowserUk (Patriarch) on Jun 24, 2007 at 08:05 UTC | |
|
Re: Howto avoid large hard-coded else-if function calls
by FunkyMonk (Bishop) on Jun 24, 2007 at 08:04 UTC | |
|
Re: Howto avoid large hard-coded else-if function calls
by vkon (Curate) on Jun 24, 2007 at 07:56 UTC | |
|
Re: Howto avoid large hard-coded else-if function calls
by grinder (Bishop) on Jun 24, 2007 at 10:22 UTC | |
|
Re: Howto avoid large hard-coded else-if function calls
by shmem (Chancellor) on Jun 24, 2007 at 08:09 UTC | |
|
Re: Howto avoid large hard-coded else-if function calls
by friedo (Prior) on Jun 24, 2007 at 12:47 UTC | |
|
Re: Howto avoid large hard-coded else-if function calls
by jdporter (Paladin) on Jun 25, 2007 at 11:51 UTC | |
by jdporter (Paladin) on Jun 25, 2007 at 13:13 UTC | |
by BrowserUk (Patriarch) on Jun 25, 2007 at 12:15 UTC |