I have been writing Perl code for (1) week as of today. Thanks to the beginner user e:mail, and thank you to John Edwards, and [EMAIL PROTECTED], and other input I have learned from this page. I have put togther the following. It works well, and is doing what I want it to do. Except, 1 little problem remains. Please read the below, and I would appreciate any advice. I have tried trim and chomp with no results. Thank You Susan. (P.S. - I am not a student - I work in the ITC department.)
This routine opens 15 different school files, for this example, I have shorten it to 1 school. It creates a data file call STNAME.DAT. This file contains, last name, first name, student #, and school #. I then open STNAME, look for duplicates using ( first 5 char's of last name+1 char of first name). Look in arrary does it exist. if yes, add a counter to name. I then store this in a result file, called result.dat. What my question is, how do I strip out the spaces on the last name if the last name is not 5 char. long. example: ASHE J 123456 396. Example: open(FILE396,"396.TXT") or die $!; # open file for input SCHOOLS INDIV. FILE print OUT substr($_,12,5),substr($_,30,1),substr($_,3,9)," ",substr($_,0,3),"\n" while <FILE396>; close(FILE396); # CREATE result file, look for duplicates add counter on name, rebuild string my %names; open(I,"STNAMES.DAT") or die"name: $!\n"; # open student consolidated names open(O,">results.dat") or die"results: $!\n"; # result file open output foreach $line(<I>) { my $name=substr($line,0,6); my $workingname=$name; my $counter=1; while(exists($names{$workingname})) { $workingname=$name.$counter; $counter++; } $names{$workingname}=$workingname; print O $workingname,substr($line,7,13),"\n"; # add back Student # # School # } # The file below is results.dat (if last name is less than 5 chars. it fille in spaces. I want the spaces gone) LINDSD 11115 314 LINDS1 13065 314 LINDS2 225 396 LINDS3 11125 378 LOCK S 90174 314 LOKE J 14013 314 LONDOS 13009 314 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]