On Jan 6, 2004, at 2:08 PM, [EMAIL PROTECTED] wrote:


Yo.....

what Up.


I read in Learning Perl that there are no such constructs
like a case statement. Is there something similar or did I misread this?

As folks have already pointed to both the classic perlfaq, and implied that one should consult

perldoc Switch

which if you are not on perl5.8 can be
downloaded from the CPAN from
<http://search.cpan.org/~dconway/Switch-2.09/Switch.pm>


 Also what about functions and function calls,
do these exits or does the subroutines replace these?
[..]

This of course brings us to the more interesting
side of the swtich/case statement problem - namely
what are you trying to do with them, and have you
thought about the classic 'dispatching table' type
of solution - say something like

        my %process = (
                start => \&do_start,
                stop => \&do_stop,
                test => \&do_test
        );

        if ( defined( $process{$ARGV[0]}))
        {
                $process{$ARGV[0]}(@ARGV);
        } else {
                print "issued invalid command: $ARGV[0]\n";
        }

        sub do_start { ... }
        sub do_stop  { ... }
        sub do_test  { ... }

you will notice that this is similar to the classic
init script most folks have seen as say

        #!/bin/sh
        
        case "$1" in
                "start") do_start ;;
                "stop")  do_stop ;;
                "test")  do_test ;;
                *) echo "i do not know how to to $1" ;;
        esac

So it's sorta a case of what exactly were you trying
to do with the case like statement???


ciao drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to