Solved

Delimited Text File Database

Posted on 2006-10-27
8
172 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
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
Comment Utility
$_ = "<font color=0000".($email{$_}?"FF":"00").">$_</font>" for $e1,$e2,$e3,$e4;
0
 

Author Comment

by:precision
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

763 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

10 Experts available now in Live!

Get 1:1 Help Now