Sorry about the previous post...I am still learning the rules around here
As stated before I want to read in text file, find three items, combine them, and create a code
I am having trouble trying to figure out what's going on with the subroutine, and several other places
my apologies in advance
#! /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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.