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 = ""}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|