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


In reply to Re: stuck on code by davido
in thread stuck on code by mwill66

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.