> -----Original Message-----
> From: frazzmata [mailto:[EMAIL PROTECTED] 
> Sent: Monday, September 08, 2008 10:13
> To: beginners@perl.org
> Subject: comparing text files, in a way
> 
> I am writing a program where I want to be able to locate information
> regarding a person in one file, if they appear in another.
> 
> For instance:
> 
> I have a file that just has student IDs (for students that are new)
> 
        I would load the the larger one into a hash using the id as the
key and then read the one with ID's only, marking on the hash which one
had hits. Then by how you did the marking, you could print out and have
control over the sorting, print format etc.  Obviously need some error
checking so if on the id only file, but not on your master, you would
need to report on that. 

        A hash, check the id on second file in hash, mark for each used.
Then you can use the hash for all your printouts.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449           FAX
http://fedex.com/us 


> It has a long list of Student IDs like this:
> 
>  100955
> 104024
> 564765
> 123456
> 765437
> 123321
> 323999
> 444555
> 
> Then there is another file that has information such as this:
> 
> 100955   BLow-Gomez, Joseph   M MEX.AMER.  QHUTC012
> 101121   NOBODY, GARY E.      M CAUC       COCO0502
> 101985   sOMEBODY, RICHARD    M CAUC       COCO0404
> 102989   GUY, JON G.  M BLACK      COCO0505
> 103257   DUDE, MICHAEL D.     M CAUC       TENN3306
> 104024   CHICK, JENNY A.      M BLACK      QHUTJ005
> 104272   GIRL, JOSIE R.       M MEX.AMER.  TENN3201
> 104586   BOY, TERRELL L.      M BLACK      QHUTG013
> 104802   SOMEFELLA, JAMES D.  M BLACK      QHUTA001
> 105011   PERSON, JAMES J.     M CAUC       COCO1909
> 106455   HUMAN, STEPHEN J.    M CAUC       YUMAD012
> 106461   HOMOSAPIEN, RODNEY   M BLACK      QHUTB014
> 106953   ERECTUS, JAVIER      M MEX.NAT.   COCO0701
> 107461   THIRTYTWOTEETH, TIMOTHY      M CAUC       TENS0904
> 108594   TACOBELL, ARNOLD G.  M MEX.AMER.  TENN2303
> 
> (all tab delimited)
> 
> For each id in the first file, I want to match it in the second file
> and then print all the info contained in the second file into a third
> file that contains only the people that were in both.
> 
>  This is essentially what I have so far...
> This only gets me up to a certain point. It doesn't do the
> comparison.
> 
> $ifile = "roster.txt";
> $ofile = "output.txt";
> 
> 
> 
> open(IFILE, "$ifile");
> open(OFILE, "+>$ofile");
> 
> #store the file in an array.
> 
> my @guys;
> 
> while ($line = <IFILE>) {
>               if ($line =~ /^\d\d\d\d\d+/) {
> 
>                               $things = substr $line,0,51;
>                                       push @guys,$things;
>                               }
>               }
>               foreach $line (@guys) {
>                       if ($line =~ /^0/) {
>                               ($trash,$rest) = split(/^0/,$line);
>                               print OFILE "$rest\n";
>                       }else{
>                               print OFILE "$line\n";
>                       }
> 
>                       }
> 
> 
> 
> 
> close IFILE;
> close OFILE;
> 
> $tfile = "testing.txt";
> 
> 
> open(IFILE, "$ofile");
> open(TFILE, "+>$tfile");
> 
> while (<IFILE>) {
>       chomp;
>       my ($adc, $record) = split(/\t+/,$_);
>       push @{$table{$adc}}, $record;
>     }
> 
>     foreach $adc (sort keys %table) {
> 
>       print TFILE "$adc ";
>       my @records = @{$table{$adc}};
>         print join ', ', sort @records;
> 
>       print TFILE "\n";
>     }
> 
>     close IFILE;
>     close TFILE;
> 
> $cfile = "changes.txt";
> $output = "output.txt";
> 
> open(TFILE, "$tfile");
> open(TFILE, "$cfile");
> open(OFILE, "+>$output");
> 
> 
> I am open to a complete rewrite of course, since the above code only
> gets me the file to compare to (the one with the info in it) it does
> not do the comparison (obviously)
> Please help
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
> 
> 
> 

**********************************************************************
This message contains information that is confidential and proprietary to FedEx 
Freight or its affiliates.  It is intended only for the recipient named and for 
the express  purpose(s) described therein.  Any other use is prohibited.
**********************************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to