in reply to stuck on code

The only question I see is this:

my $key = $str; is this even possible, i remember doing it in some oth +er language

$str receives a value passed into the subroutine when it is called. So yes, it's possible. But sub submain ($head,$str) isn't. Eliminate the ($head,$str) portion of your subroutine declaration.

Next, what you're doing makes no sense to me. Why would you pass in a value, $str, and then iterate over each line of a file, and for each line, increment the value of the hash element indexed to the string passed into the sub? And even if your goal is to get a line count (which is what you're almost doing), why bother printing the string passed into the subroutine again and again? Finally, why return from inside of a while() loop, guaranteeing that it will loop only one time, incrementing $count{$key} just once?

The syntax errors come down to trying to write Perl code without knowing Perl. However, the logic errors seem to be the result of trying to write code without knowing how to program. We are going to have a hard time helping when the only spec we have to work with is code that won't compile, and that even if it did, had logic errors so prominent that it's impossible to determine what the code is actually supposed to do if the errors were all fixed.

I think the only way you're going to get help on this one that is useful to you is if you post some questions in plain old English that are comprehensible to us.


Dave