Solved

Delimited Text File Database

Posted on 2006-10-27
8
173 Views
Last Modified: 2010-03-05
This is in an existing program so I have to stick with the delimited text file instead of using mysql, here is what I have and what I want to do.  I tried numerous things, nothing worked as of yet:

I have 2 separate delimited text files, we will call one FILE1 and the other FILE2.

FILE1 has this type of format:
$count|$wa|$id|$n1|$e1|$n2|$e2|$n3|$e3|$n4|$e4

FILE2 has this type of format:
$id|$wa|$ww|$q1|$q2|$q3|$fullname|$zip|$phone|$email

Here is what I am trying to do:
I want to open FILE2 and see if the FILE2 $email is in FILE1 of either $e1 $e2 $e3 $e4
IF SO then for simple sake make $e2 = "FOUND";

It just seems like I have to open FILE2, pull out the $email, then open the FILE1 and check to see if there is a match, if yes then $e2 = "FOUND"; if not then go to FILE2 and get the next $email.  I either crash or it get stuck in infinite loop.  It seems simple but also it seems like there will be quite a few iterations being done.  HELP!!!!

0
Comment
Question by:precision
  • 4
  • 4
8 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17820508
when you say make $e2 = "FOUND"; are you saying you want to change FILE1?
if so, $e2 would only match $email when $email eq "FOUND", am I understanding that right?
It also sounds like there are more than one line in FILE2
are there also more than one line in FILE1?
If so, what do you want do make $e2 = "FOUND" for all lines?

what are you trying when you either crash or it get stuck in infinite loop?
0
 

Author Comment

by:precision
ID: 17820576
No, not changing any data and yes FILE1 & FILE2 has more than one line.

Say for instance in FILE2 there are 10 lines of data, so there is 10 unique $email (s) I want to take say FILE2 the first line $email and check and see if it is anywhere in the complete FILE1 database and so on.  Therefore, FILE1's database will be checked 10 times with the 10 $emails (s) from FILE2.

Loop 1: Open FILE2 and get first $email....then open FILE1 and check to see if $email is found anywhere in FILE1 mainly $e1, $e2, $e3, $e4...if so just have say $e2 = "FOUND";....not changing the actual data piece in FILE1 but temporarily renaming the data piece.

Program is up and running so I have to work with what I have, I have to keep two separate databases.

I hope this makes more sense....Thanks!
0
 
LVL 84

Expert Comment

by:ozo
ID: 17820812
I'm still not quite sure I understand you, but I'll give some code to do what I think you are saying so you can tell me how it compares to what you want

open FILE2,"<filename2" or die "Can't open filename2 $!";
while( <FILE2> ){
   chomp;
   $email{(split/\|/)[-1]}++;
}
open FILE1,"<filename1" or die "Can't open filename1 $!";
while( <FILE1> ){
  chomp;
  my($count,$wa,$id,$n1,$e1,$n2,$e2,$n3,$e3,$n4,$e4)=split/\|/;
   $email{$_} and $_ = "FOUND" for $e1,$e2,$e3,$e4;
   print "$count|$wa|$id|$n1|$e1|$n2|$e2|$n3|$e3|$n4|$e4\n";
}
0
 

Author Comment

by:precision
ID: 17821369
Ok...I think we are on the same track, getting close, here is my actual routine from your help...where you see the *** is what I put in, killed it, but trying to make the print statement occur "if only" $email from FILE2 equals any of the data pieces from FILE1 ( $e1,$e2,$e3,$e4)

open (FILE2,"../gt/$in{'id'}/A.txt") || die "Can't open filename2 $!";
while( <FILE2> ){
   chomp;
   $email{(split/\|/)[-1]}++;
}
open (FILE1,"../gt/$in{'id'}/B.txt") || "Can't open filename1 $!";
while( <FILE1> ){
  chomp;
  my($count,$wa,$id,$n1,$e1,$n2,$e2,$n3,$e3,$n4,$e4)=split/\|/;
***if ($email{$_} and $_ = "FOUND" for $e1,$e2,$e3,$e4)
***{
***   print "$count|$wa|$id|$n1|$e1|$n2|$e2|$n3|$e3|$n4|$e4\n";
***}
}
exit (0);
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 84

Expert Comment

by:ozo
ID: 17821508
open (FILE2,"../gt/$in{'id'}/A.txt") || die "Can't open ../gt/$in{'id'}/A.txt $!";
while( <FILE2> ){
   chomp;
   $email{(split/\|/)[-1]}++;
}
open (FILE1,"../gt/$in{'id'}/B.txt") || "Can't open ../gt/$in{'id'}/B.txt $!";
while( <FILE1> ){
  chomp;
  my($count,$wa,$id,$n1,$e1,$n2,$e2,$n3,$e3,$n4,$e4)=split/\|/;
  if ( grep {$email{$_} and $_ = "FOUND"} $e1,$e2,$e3,$e4
   {
      print "$count|$wa|$id|$n1|$e1|$n2|$e2|$n3|$e3|$n4|$e4\n";
   }
}
exit (0);
0
 

Author Comment

by:precision
ID: 17825215
Ok, seems to run without crashing, fantastic, is there a way instead of having $email turn into "FOUND" that if $email is equal to either $e1,$e2,$e3,$e4 and have this scenario happen:

Say...

$email say is me@me.com and...
$e1 = a@me.com
$e2 = b@me.com
$e3 = me@me.com
$e4 = d@me.com

Then it would make $e3 = "<font color=0000FF">$e3</font>";
and the rest $e1,$e2 & $e4 would be = "<font color=000000">$e()</font>";
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 17831870
$_ = "<font color=0000".($email{$_}?"FF":"00").">$_</font>" for $e1,$e2,$e3,$e4;
0
 

Author Comment

by:precision
ID: 17833347
Nice!....I am going to fire up another session since I need to adjust, I tried a few mods but crap they don't work!!!!  Look for my next post....
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Input from stdin for perl 6 118
Reading fields from the text file. 4 92
perl script to search for files containing text 3 73
read an xml file in perl 2 14
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now