Ordinarily, you will want 'lexical' variables. Lexical is a bit of jargon which means that the variable is in scope (i.e. is valid) over a single chunk of your program. You can declare your variables with: my $speakerID; or several at-a-time with my ($speakerID, $minres); etc. Your initialisation of %GoodWords can also be turned into a declaration, by writing my %GoodWords = ( ... );
The purpose of doing this is primarily organisational. If you accidentally mis-spell a variable name you'll get a warning because you're attempting to use an undeclared variable. It also has more significant benefits when you're writing larger, more structured programs.
Next - your regular expression is failing to match your initial lines. This is because you aren't matching the closing tag correctly, it should be </strong>. However, as you've probably noticed, you can't put a / directly in your regexp as is, because you're using that character to delimit the beginning and end. The easiest solution is to use another character to delimit the match (in which case you also need a leading 'm', like this: m!<strong>(S[\w\-]+)</strong>:.*Gender:\s+(Male|Female)!.
Also, if you've matched a line as defining a user, you don't want to carry on and try and process it as a spoken sentence. So you should either use a big if/else in the loop or, better, simply go around for the next iteration of the loop. (i.e. put a next in the if (m!<strong>..!) { ...; next; }
If your sentence recognising match fails (for example on a blank line), you might want to skip the rest of the loop. You could put an if(!/.../) { next; } in there to do this. But perhaps preferably (since we all make mistakes writing regexps from time to time, it is better to explicitly ignore blank lines and then warn if your regular expression doesn't match.
You can print multiple things in a print statement like this: print "Male:", $minresgen {"Male"}, "\n"; (I've also put a newline on the end there).
I don't know if you're meaning to print out the Male/Female info for every line. I suspect not, so you'll probably want to move those print statements out of the main loop and put them afterwards. If you do, you might want to initialise those items to zero so that you don't get warnings if a particular line doesn't contain both male and female.
Sorry for a long rambling post, but it looks like you've come a long way yourself - good look on getting the rest of the way.
In reply to Re: minimal response program code problem
by jbert
in thread minimal response program code problem
by Katy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |