frazzmata wrote:
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)

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.

my %ids;
while ( <STUDENT_IDS> ) {
    chomp;
    next unless /^\d{6}$/;
    $ids{ $_ }++;
    }

while ( <SECOND_FILE> ) {
    my ( $id ) = split /\t/;
    next unless exists $ids{ $id };
    print THIRD_FILE;
    }


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";

my $ifile = "roster.txt";
my $ofile = "output.txt";

open(IFILE, "$ifile");
open(OFILE, "+>$ofile");

You should *always* verify that the file opened correctly:

open IFILE, '<', $ifile or die "Cannot open '$ifile' $!";
open OFILE, '>', $ofile or die "Cannot open '$ofile' $!";

[ *snip* ]



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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


Reply via email to