Hi, I have a script written below (by John Krahn and WC-Sx-Jones from this mailing list) which changes the file format from: #cat PSCS-ORIG abinabdu adanie2 agibson agoh1 aiabouse akko alau alee1 alee2 amitb amohdali amshams anmohand to the format listed below when printing it out to the standard output:
abinabdu adanie2 agibson agoh1 aiabouse akko alau alee1 alee2 amitb amohdali amshams anmohand I have another file(employeeID.txt) which having the format: 1066:hsridhar 7937:ssmn 7979:kpushpar (output truncated ... ) where the numbers 1066 - 7979 represents the user's employee ID. Then names [hsridhar - kpushpar] represents the usernames themselves. I would like to loop through the employeeID.txt file, but using the hash keys created in the earlier script as the keys to retrieve the employeeID corresponding to the usernames in the hash key. Note that the names appearing in the hash may or may not appear in the employeeID.txt file. My problem: I'm not sure of how I could insert the employeeID values correponding to the key values from the %count hash(used during the conversion of the file format), then search and print the corresponding employeeID based on the key values (usernames) from %count hash. Below is my script used for this task: Could anyone kindly help me out? Thanks. tigger > cat readID.pl ############## CONVERTS FILE OUTPUT FORMAT ######################################## my $file = 'PSCS-ORIG'; open INFILE, $file or die "Cannot open $file: $!"; my @entries = map "$_\n", map split, <INFILE>; print @entries; close INFILE; my %count; while (<DATA>) { for my $word (split) { next unless $word =~ /\w/; $word =~ s/^\W+//; $word =~ s/\W+$//; $count{lc $word}++; ## hashes of lower-case characters } } for my $word (sort keys %count) { print "$word\n"; } ################## READS DATA FROM employeeID.txt FILE INTO HASH ########################## $file = "/home/data/employeeID.txt"; open(FILE, $file) or die ("Cannot open $file $! "); @array = <FILE>; close(FILE); for($i=0;$i<@array;$i++){ @tmp=split(/:/, $array[$i]); $wwid = $tmp[0]; $userName = $tmp[1]; print "\$wwid = $wwid \n"; print "\$userName = $userName \n"; foreach $rec ($userName){ ##############THIS IS THE PART WHERE I'M HAVING PROBLEMS ################ if(exists($record{$userName})){ print "Here, $userName is $record{$userName} \n"; } else{ print "No such element \n";} } foreach $word (keys %count){ print } } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>