Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: A Case with 5 Var's

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


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

its an qry for a local unique system wich is not public, it needs defined stuff so i need to check if a var is filled or not so i can create a exact matching qry

example: only $name and $plz is filled with Mueller and 55555 both are strings btw, then the qry looks like
::5544$nameGDFTxxxxx$plz::0:
for each possibility is another qry defined ;/
kd ultibuzz


Comment on Re^3: A Case with 5 Var's
Re^4: A Case with 5 Var's
by eric256 (Parson) on Jan 25, 2007 at 15:38 UTC

    It depends how your query is built. Hopefully each variable is responsible for just one section, then you just build the query up as you go.

    my $qry = ""; my $name = "Mueller"; my $plz = "55555"; if ($name) { $qry .= "::5544$nameGDFT"; } if ($plz) { $qry .= "xxxxx$plz::0:";} print $qry;

    Since I have no idea what kind of query that is I had no idea what parts go where, but hopefully that gives you and idea how it can be done.

    If your query is completly dependent on the elements available then you could combine your ifs together some for readability at least

    if ($name && $vorname && $plz && $tel && tel49) { $qry = "whatever +" } elsif ($name && $vorname && $plz && $tel) { $qry = "whatever +2" } elsif ($name && $vorname && $plz) { $qry = "whatever +3" };

    That is not the recommended solution, just one of the many ways to do it.


    ___________
    Eric Hodges

      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

        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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-12-25 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls