g man has asked for the wisdom of the Perl Monks concerning the following question:
#! /usr/bin/perl5 require "hash.pl" #! /usr/bin/perl5 $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);
Edit: g0n - fixed code tags and formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: filehandles and such
by turnstep (Parson) on Apr 19, 2000 at 17:37 UTC | |
by g man (Initiate) on Apr 26, 2000 at 06:26 UTC | |
|
Re: filehandles and such
by btrott (Parson) on Apr 19, 2000 at 10:24 UTC |