#! /usr/bin/perl $file1path = "c:/Documents and Settings/bob/My Documents/Research/"; $file1name = "AK_Schools_Student_Race_By_Grade_2010091001.csv"; $file1= $file1path.$file1name; $file2path= "c:/Documents and Settings/bob/My Documents/Research/"; $file2name = "AK_School_Student_Pop_By_Grade_2010091001.csv"; $file2=$file2path.$file2name; $file3path= "c:/Documents and Settings/bob/My Documents/Research/Testing"; $file3name = "Combined_File.csv"; $file3 = $file3path.$file3name; $counter = 0; $counter2 = 0; open (f1, $file1) ; open (f2, $file2) ; open (f3 , ">>$file3"); open( f4, ">>c:/Documents and Settings/bob/My Documents/Research/Testing/looping_file.csv"); while () { chomp; @f1_array=split (",") ; $f1_state = @f1_array[0]; $f1_district_name =@f1_array[1]; $f1_district_key = @f1_array[2]; $f1_school_name=@f1_array[3]; $f1_school_key=@f1_array[4]; $f1_site_guid=@f1_array[5]; $f1_student_grade=@f1_array[6]; $f1_count_of_students=@f1_array[7]; $counter=$counter+1; #print "$f1_state , \n"; #print "$f1_district_name , \n"; #print "$f1_district_key , \n"; #print "File 01 - $counter, \n"; while () { chomp; @f2_array=split (","); $f2_state = @f2_array[0]; $f2_district_name =@f2_array[1]; $f2_district_key = @f2_array[2]; $f2_school_name=@f2_array[3]; $f2_school_key=@f2_array[4]; $f2_site_guid=@f2_array[5]; $f2_student_grade=@f2_array[6]; $f2_student_race=@f2_array[7]; $counter2=$counter2+1; $f2_student_race_count=@f2_array[8]; #print f4 "$f2_state , "; #print f4 "$f1_state , \n"; #print f4 "$f2_district_name , "; #print f4 "$f1_district_name , \n"; #print f4 "File 02 District Key - $f2_district_key , "; #print f4 "File 01 District Key - $f1_district_key, \n"; #print f4 "$f2_school_name, "; #print f4 "$f1_school_name, \n"; #print f4 "File 01 - $counter,"; #print f4 "File 02 - $counter2, \n"; } if (($f1_state eq $f2_state) && ($f1_district_key eq $f2_district_key)) { print f3 "$f1_state , "; print f3 "$f1_district_name ,"; print f3 "$f2_district_name ,"; print f3 "$f1_district_key ,"; print f3 "$f2_district_key ,"; print f3 "$f1_school_name , "; print f3 "$f1_school_key , "; print f3 "$f1_site_guid ,"; print f3 "$f1_student_grade , "; print f3 "$f1_count_of_students ,"; print f3 "$f2_student_race , \n"; } } close (f1); close (f2);