in reply to Re: Re: Re: My vacation depends on it
in thread My vacation depends on it

As much as I like a(some) nice %hash, I also like a good switch for clarification, it beats those if'n'else's Check out perlman:perlsyn and How do I create a switch or case statement? for more clarification.
$cat = 'ata'; SWITCH: for ($cat) # make $_ = $cat, you could do it by hand { # syntaxt # whatever test on $_ && do { $this = 'if test passed'; last;}; (length $_ > 1) && do { die "\$cat must be one letter not: `$cat'" +; last;}; /t/ && do { $catfile = "notitec.html"; last; }; /a/ && do { $catfile = "notiagro.html"; last; }; /d/ && do { $catfile = "notideportes.html"; last; }; /h/ && do { $catfile = "notihogar.html"; last; }; /r/ && do { $catfile = "notirecrea.html"; last; }; /s/ && do { $catfile = "notisociales.html"; last; }; die "unknown value for \$cat: `$cat'"; # could just as easily be the default value }
P.S. Are you a sadist?(no -w strict, you must -w strict)

update: I agree tilly, not that i'd dare disagree with you ;). I feel <10 and not gonna expand, is a good time to use one.

 
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void

perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Replies are listed 'Best First'.
Re (tilly) 1: (crazyinsomniac: switch) Re: (4) My vacation depends on it
by tilly (Archbishop) on Apr 04, 2001 at 07:47 UTC
    The scanning logic of a switch is flexible and easy for you to understand and see, but if you have long lists of options that you are processing within a loop, it will be a lot slower than dispatching on a hash lookup. If you can arrange to do it the latter way, it is generally worth doing so.

    Just something to be aware of.