Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^5: A Case with 5 Var's

by ultibuzz (Monk)
on Jan 25, 2007 at 16:11 UTC ( #596532=note: print w/ replies, xml ) Need Help??


in reply to Re^4: A Case with 5 Var's
in thread A Case with 5 Var's

yep it depends on the elements, and with && i need much more if and elsifs.
in my example i don't need to check $name later on when it was not there so its much shorter, all var's combination with && are a bit more ;)
kd ultibuzz


Comment on Re^5: A Case with 5 Var's
Replies are listed 'Best First'.
Re^6: A Case with 5 Var's
by eric256 (Parson) on Jan 25, 2007 at 17:58 UTC

    Actually I would think it comes out to the same number of if's but in a more readable format where you can see immediately which elements had to be true to force that query, either way I would recommend building the query on the fly if that is at all possible. Either way this is 25 lines instead of 70ish.

    if ($1 && $2 && $3) { #a } if ($1 && $2) { #b } if ($1 && $3) { #c }

    versus

    if ($1) { if ($2) { if ($3) { #a } else { #b } } elsif ($3) { #c } }

    I got a little bored and tried it out. Unless i screwed something up I think you are messing several combinations.

    if ($name && $vorname && $plz && $tel && $tel49) { $qry = ""} elsif ($name && $vorname && $plz && $tel) { $qry = ""} elsif ($vorname && $plz && $tel && $tel49) { $qry = ""} elsif ($name && $plz && $tel && $tel49) { $qry = ""} elsif ($name && $vorname && $plz) { $qry = ""} elsif ($name && $plz && $tel) { $qry = ""} elsif ($name && $tel && $tel49) { $qry = ""} elsif ($vorname && $plz && $tel) { $qry = ""} elsif ($plz && $tel && $tel49) { $qry = ""} elsif ($name && $vorname) { $qry = ""} elsif ($name && $plz) { $qry = ""} elsif ($name && $tel) { $qry = ""} elsif ($name && $tel49) { $qry = ""} elsif ($vorname && $plz) { $qry = ""} elsif ($plz && $tel) { $qry = ""} elsif ($tel && $tel49) { $qry = ""} elsif ($plz) { $qry = ""} elsif ($name) { $qry = ""} elsif ($tel) { $qry = ""} elsif ($tel49) { $qry = ""} elsif ($vorname) { $qry = ""}

    ___________
    Eric Hodges
      and what is with the combination $vorname && tel && tel49 ;)
      i really like this idear of hash and a hash with all bitmasks
      kd ultibuzz

        Tha combination? Thats just all the combinations you where testing for in your old code. I agree bitmasks or building as you go are probably better solutions. Just giving you more than one way to do it.


        ___________
        Eric Hodges

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2015-07-29 18:42 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 (267 votes), past polls