in reply to something like switch(case) in Perl

No too hard. Use RE's and $_ (well sort of :) ).
SWITCH: foreach (keys %house){ #Note: the key is stuffed in $_ /^person$/ and do { print "My name "; #Note: the Regex works on $_ p_CC(); next SWITCH; } /^AB$/ and do { print "AB "; p_AB(); next SWITCH;} }


BTW this is a FAQ - 'perldoc -q switch' which will lead you to How do I create a switch or case statement.

grep
grep> cd pub
grep> more beer

Replies are listed 'Best First'.
Re: Re: something like switch(case) in Perl
by agustina_s (Sexton) on Jan 23, 2002 at 08:49 UTC
    Thanksss
Re: Re: something like switch(case) in Perl
by agustina_s (Sexton) on Jan 24, 2002 at 07:09 UTC
    Hi Grep... I want ask about the switch statement that you have suggested.. About the speed... will it be just the same with:
    If(...=~...){ do something } elsif(....=~)( do some other thing } ... else {...}
    Since it also compares the $_ with /.../. Thanks...
Re: Re: something like switch(case) in Perl
by grep (Monsignor) on Jan 24, 2002 at 09:24 UTC
    Straight comparisions ('eq' or '==') will always be faster than regexp's. (You can try to make your regexp's faster by anchoring and using literials)

    The main focus should not be speed at the cost of maintainibilty. If it looks cleaner and reads well go with that solution. Ovid has written an excellent post about Premature Optimization.

    grep
    grep> cd pub
    grep> more beer