[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [school-discuss] English teacher apps



Robin, hey! thanks!
Do you mind if I show this script to other people to get some help getting it to work? I just ran it and got some compile errors...

$perl perlconc.pl
syntax error at perlconc.pl line 5, near "open "
#here'e the line: open (TEMPFILE,"+>tempfile.txt");
Execution of perlconc.pl aborted due to compilation errors.

I'm really looking forward to getting this to work and I do appreciate the speed in which you responded to my requests! Once it's working I'll have my students using it in within a day!
best
Dennis

robin wrote:
Dennis Daniels wrote:

Hello Robin,
I actually found and downloaded perlconc :) I'm not much of a perl guy (diver?) but have had some small success with one-liners in perl. I was looking at your app as as a standalone app... do you still have a standalone version? I've found that concordances really help students understand the correct usage of words ergo the interest.

A very crude early version is attached.

Robin


------------------------------------------------------------------------

#!/usr/bin/perl

$default="/home/user/corpus.txt" # Change file name to your default corpus

open (TEMPFILE,"+>tempfile.txt");

&intro;
print "\n OK, I think I've got that.\n";
&mainmenu;

sub intro {
($username) = getpwuid ($<);
if ($username ne "fast") {
print "Hello, $username !\n";
}
print "Which file contains the corpus you want to operate on?\n";
print "Type the full address of the file, e.g. /home/ayse/homework.txt, \n or just hit Return for the default corpus\n"; $input = <>;
chop $input;
open (CORPUS,"$input") || open (CORPUS,"$default") || &intro; }


sub mainmenu {
print "\nWhat would you like to do?\n";
print "1. Word frequency count\n";
print "2. Concordance\n";
print "3. Quit\n";
$choice = <>;
chop $choice;

if ($choice == 1) {
&wordcount;

} elsif ($choice == 2) {
&concmenu;
} elsif ($choice == 3) {
print "Bye!\n";
}
else {
print "That's not a number from 1 to 3!\n";
&mainmenu;
}
}

sub wordcount {
print "Enter word to count\n";
$totalwords = 1;
$wordcount = 0;
$searchstring = <>;
chop $searchstring;
while (<CORPUS>) {
if (/$searchstring/ig) {
$wordcount++;
}
$totalwords++;
}
$wordspermillion = $wordcount / $totalwords * 1000000;
$wordspermillion = $wordspermillion + 0.5;
$wordspermillion = int ($wordspermillion);
print "In a corpus of $totalwords words, $searchstring occurs $wordcount
times.\n This gives a word frequency of $wordspermillion words per million.\n";
&mainmenu; }

sub concmenu {
print "Enter the word or phrase you want to search for\n";
$searchstring = <>;
chop $searchstring;
print "Search for $searchstring ? (y/n)\n";
$choice = <>;
chop $choice;
if ($choice eq "y") {
&concordance;
} elsif ($choice eq "n") {
&concordance;
} else {
print "Huh?\n";
&mainmenu;
}
}

sub concordance {
$results = "Concordance for $searchstring\n";
while ( $line = <CORPUS>) {
if ($line =~ $searchstring) {
$next = <CORPUS>;
print "$prev $line $next\n\n";
print TEMPFILE "$prev $line $next\n\n";
$results .= "$prev $line $next\n\n";
}
$prev = $line;
}
&saveit;
}

sub saveit {
print "Do you want to save this file? (y/n)\n";
$choice = <>;
chop $choice;
if ($choice eq "y") {
print "Enter file name.\n";
$filename = <>;
chop $filename;
if (-e "$filename") {
print "Hold on, there's already a file called $filename . \n Are you sure you want to overwrite it? (y/n)\n";
$choice2 = <>;
chop $choice2;
if ($choice2 eq "y") {
open (NEWFILE, ">>$filename");
print NEWFILE "$results\n";
close (NEWFILE);
} elsif ($choice eq "n") {
&saveit;
} else {
print "Huh?\n";
&saveit;
}

} else {


open (NEWFILE, ">>$filename");
print NEWFILE "$results\n";
close (NEWFILE);
}
} elsif ($choice eq "n") {
&mainmenu;
} else {print "Huh?\n";
&saveit;
}
}