yoda54 has asked for the wisdom of the Perl Monks concerning the following question:
What's better way to write this? I need something that will execute the right function based on the number of inputs. Eventually, what is a way to do this for N inputs?
Thanks for any help!
sub input { if ( $_[0] =~ /(.+)\s+(.+)\s+(.+)/) { print "3 params\n"; } elsif ( $_[0] =~ /(.+)\s+(.+)/) { print "2 params\n"; } elsif ( $_[0] =~ /(.+)/) { print "1 params\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl newbie question.
by Ratazong (Monsignor) on Mar 16, 2010 at 09:53 UTC | |
by kiruthika.bkite (Scribe) on Mar 19, 2010 at 09:24 UTC | |
|
Re: Perl newbie question.
by Utilitarian (Vicar) on Mar 16, 2010 at 09:57 UTC | |
|
Re: Perl newbie question.
by JavaFan (Canon) on Mar 16, 2010 at 11:23 UTC | |
|
Re: Perl newbie question.
by jethro (Monsignor) on Mar 16, 2010 at 10:00 UTC |