Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Problems with scripts

by quidity (Pilgrim)
on Nov 27, 2000 at 03:11 UTC ( #43416=note: print w/ replies, xml ) Need Help??


in reply to Problems with scripts

You might want to rewrite this section of code so that it is a little clearer:

if ($location eq ""){ &main }elsif ($location eq lc("misc")){ &misc }elsif ($location eq lc("links")){ &links }else{ default('Where are you trying to go?'); }

by using a switch construct (which is really an abuse of a looping construct):

SWITCH: for ($location) { /^$/ && do {&main() ;last SWITCH}; /^misc$/i && do {&misc() ;last SWITCH}; /^links$/i && do {&links() ;last SWITCH}; default('Where are you trying to go'); # catch anything else }


Comment on Re: Problems with scripts
Select or Download Code
Replies are listed 'Best First'.
Re: Re: Problems with scripts
by arturo (Vicar) on Nov 27, 2000 at 03:21 UTC

    I like the "switch" idea quite a bit, myself. Here's something you might do right off the bat: those lc "misc" calls are pointless (the string IS in lower case, that's the part you control). So, at the top, something like  my $location = lc $query->param('place) or 'links'; # or a sensible default

    Which converts the value you *can't* control to lowercase . One nice thing about the "switch" idea is that you can fall through to a default if the value of the parameter isn't valid.

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://43416]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2015-07-08 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls