A nudge in the right direction (Perl)

Associate
Joined
6 Dec 2010
Posts
615
Location
Belfast
I normally do anything but ask for help with these things but it's becoming quite infuriating after trying a few methods of doing this. Obviously I'm missing the right design in my head for this so if anyone could be kind enough to at least give me a heads up on how to complete this code (it's literally the last thing I need to do.)

Code:
sub processForm(){



print start_html( 'Testers' );

$testersFile = ">>testers.txt";
open (OUTFILE, $testersFile) || die "Cannot open $testersFile : $!";

$surname = param('surname');
$forename = param('forename');
$name = uc($surname.'_'.$forename);
$num = param('ext_num');
$email = param('email');
$faculty = param('faculty');


						

print OUTFILE "$name,$num,$email,$faculty\n";

print '<center>You have been registered as a tester for the UITSD 
software suite with the following details:</center>';
print br;
print "<center><table border=1>
<tr>
<td>Name</td><td>$forename $surname</td>
</tr><tr>
<td>Extension number</td><td>$num</td>
</tr><tr>
<td>Email</td><td>$email</td>
</tr><tr>
<td>Faculty</td><td>$faculty</td>
</tr>
</table></center>";

close (OUTFILE);

####INSERT CODE####

print end_html;
}

Essentially, I need to open the file (testers.txt) and then count how many times a particular word/faculty shows up. Then I'll print to screen, "There are $count testers in the $faculty faculty."

If I get answers of "do your own homework" I won't complain but I thought I might as well before I pull my hair out. :)
 
IIRC, you can find all matches within a string using regex on a while loop, something like -

while ($(yourString) =~ /m(regexPattern)/g) {
(increment interger)
}

I could be way off the mark as it's been a while, so it might be worth a google on all string pattern matching etc

http://gskinner.com/RegExr/ - Useful tool for doing RegEx Patterns
 
Last edited:
Back
Top Bottom