CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
checking before searching

 



parham_m_s
journeyman

Dec 21, 2000, 8:23 PM

Post #1 of 3 (466 views)
checking before searching Can't Post

ok... i have a database.. and i wanna search all of them. Whichever forms that have text in them will be search, the connector is &&.

So this is what i'm thinking (just testing code), but it's all wrong:

$form1 = "bleah";
$form2 = "stuff";
$form3 = "things";
$form4 = "";
$form5 = "yes";

$data1 = "bleah";
$data2 = "stuff";
$data3 = "things";
$data4 = "others";
$data5 = "yes";

if ($form1) { if ($form1 eq $data1) && }
if ($form2) { if ($form2 eq $data2) && }
if ($form3) { if ($form3 eq $data3) && }
if ($form4) { if ($form4 eq $data4) && }
if ($form5) { if ($form5 eq $data5) {
print "yes";
} else {
print "no";
}
}

of coarse, my approach is completely wrong... can anyone suggest a proper way of doing this plz?

------> more info

i just wanna know of methods people use of checking if data exists before comparing. I wanna check if data exists in a form, before searching in it. And i wanna use the && connector to search in multiple forms.

in pseudo code:
if data exists in $form1
if $form1 equals $data1
end if
AND
if data data exists in $form2
if $form2 equals $data2
end if
AND
etc etc etc.....



japhy
Enthusiast

Dec 22, 2000, 7:19 AM

Post #2 of 3 (460 views)
Re: checking before searching [In reply to] Can't Post

Well, there's no specifically simple way of doing it, although you can build some abstraction by using arrays:


Code
my @fields = ( 'blegh', 'stuff', 'things', '', 'yes' ); 
my @data = ( 'blegh', 'stuff', 'things', 'other', 'yes' );

my $ok = 1;
for (0 .. $#data) {
if ($fields[$_] and $fields[$_] ne $data[$_]) {
$ok = 0;
last;
}
}

if ($ok) { print "match found!\n" }

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


parham_m_s
journeyman

Dec 23, 2000, 5:11 PM

Post #3 of 3 (429 views)
Re: checking before searching [In reply to] Can't Post

thanx japhy, i think that's what i'm looking for... but out of curiosity, does anyone else have another solution? I'm looking for multiple ways of approaching this.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives