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: Beginner:
Fighting Duplicates

 



perlkid
stranger

Mar 3, 2000, 6:48 PM

Post #1 of 4 (779 views)
Fighting Duplicates Can't Post

 
Hi guys,

I'm trying to get this code to work for me but it seems like no matter what I do I can't get it to stop writing to the file when It is already in there.

Here is the code
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


foreach $element (@results)
{
($field1, $field2, $field3, $field4, $field5, $field6, $field7, $field8, $field9, $field10) = split(/\|/,$element);
open(c,">>/path/to/$data.db");
print c "$field3|$field5|$ENV{'MY_QUERY'}|$field4&#0124; &#0124;|\n";
close(c);

open(k,"+</path/to/$data2.db");
@all = <k>;
foreach $line (@all)
{
(@fields) = split(/\|/,$line);
}
for (@fields)
{
if ($fields[0] eq "$field1")
{}
else
{
$pr = "ok";
}
}}
if ($pr)
{
print k "$ENV{'MY_QUERY'}|\n";
}
close (k);

</pre><HR></BLOCKQUOTE>

It still prints duplicates. What do you you think is wrong?

Thanks for the help,

perlkid


brian.hayes
User

Mar 3, 2000, 8:11 PM

Post #2 of 4 (779 views)
Re: Fighting Duplicates [In reply to] Can't Post

Try changing

if ($fields[0] eq "$field1")

to

if ($fields[0] =~/$field1/)

Brian Hayes


brian.hayes
User

Mar 3, 2000, 8:34 PM

Post #3 of 4 (779 views)
Re: Fighting Duplicates [In reply to] Can't Post

with out knowing what your data from your files here is a best guess.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



foreach (@results){
($field1, $field2,
$field3, $field4,
$field5, $field6,
$field7, $field8,
$field9, $field10) = split(/\|/,$_);

open(c,">>/path/to/$data.db");
print c "$field3|$field5|$ENV{'MY_QUERY'}|$field4| &#0124; &#0124;\n";
close(c);

open(k,"+</path/to/$data2.db");
@all = <k>;
foreach (@all){
(@fields) = split(/\|/,$_);
if ($fields[0] =~/$field1/){
return; # or exit;
} elsif ($fields[0] !~/$field1/){
print k "$ENV{'MY_QUERY'}|\n";
close (k);
return; # or exit;
} else { close (k); exit; }
}
}

</pre><HR></BLOCKQUOTE>


Brian Hayes


perlkid
stranger

Mar 4, 2000, 10:57 AM

Post #4 of 4 (779 views)
Re: Fighting Duplicates [In reply to] Can't Post

 
Thanks Brain,

I tries that but It would print the word to the data base about twenty or thirty times.

I tried moving around the foreach brackets but that didn't help. I had to take out the return codes because the search engine was not working with those in there. The first data base $data is used to print the results to and the second $data2 is for the key words and I need it to stop printing the same things over and over for both data bases.

Thanks,

perlkid

 
 


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

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