g man has asked for the wisdom of the Perl Monks concerning the following question:
require hash.pl $infile="specimen100.txt" open(IN,"<$infile"); while ($line=<IN> { tr/[A-Z]/[a-z]/; #lowercase all characters s/\s+/ /; #remove extra spaces @sample=split(/[0-9][.], $line); for each (@sample) { $code=&encode($_); last if ($code); } print "code \n"; } sub encode { my(@sample=@_); $site=&findsite($sample); $specimen=&findtissue($sample); $procedure=&findproc($sample); my($code)=&assigncode($site,$specimen,$procedure); $code; } #in the subroutine below, i am trying to match the input with a hash t +able to find longest #common procedure, tissue, or site word #combine all three together to form a new code sub findproc { foreach $key (sort keys %procedure){ if ($_ =~ /$key/){ print "$procedure{$key}\n"; } } sub findtissue { foreach $key (sort keys %specimen){ if ($_ =~ /$key/){ print "$specimen{$key}\n"; } } sub findsite { # ditto for site foreach $key (sort keys %site){ if ($_ =~ /$key/){ print "$site{$key}\n"; } } if ($code) { print STDERR "$code $line"; } else { print $line; } close (IN);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problems with filehandle and more
by chromatic (Archbishop) on Apr 19, 2000 at 19:21 UTC |