Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delimited Text File Database

Posted on 2006-10-27
8
Medium Priority
?
181 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 85

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 85

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
LVL 85

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 85

Accepted Solution

by:
ozo earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans

916 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