We help IT Professionals succeed at work.

Delimited Text File Database

precision
precision asked
on
Medium Priority
192 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!!!!

Comment
Watch Question

ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
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?

Author

Commented:
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!
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
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";
}

Author

Commented:
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);
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
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);

Author

Commented:
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>";
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
$_ = "<font color=0000".($email{$_}?"FF":"00").">$_</font>" for $e1,$e2,$e3,$e4;

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
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....
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.