View Single Post
  #1 (permalink)  
Old Aug 8th, 2007, 09:55
DPhahn DPhahn is offline
Junior Member
Join Date: Aug 2007
Location: chesterfield
Age: 37
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
i am REALLY struggling

I am learning perl through skills train, i have a coding assignment to do
this is the brief:

write a perl program to analyse text files and obtain statistics
when run the program should check if an argument has been provided. if not the prog should prompt and accept input of a file name from the keyboard

the file name should be checked to ensure it is in MS-DOS format. The file name should be no longer than 8 characters and must begin with a letter of an underscore followed by upto 7 letters. the file extension should be optional, but if given it should be !.txt. if no extension is given .txt should be added

if the file name provided is not in the correct format the program should display a asuitable error

the program should then check to see if the file exists

the file should be read and checked to display crude statistics on the number of words , characrters, lines, sentences and paragraphs

you can assume the following:

character count can include whitespace and punctuation characters
each word is separated by a space, tab or new line character, except if the previous characrter was a space, tab or new line
each line is separated be a new line character
each sentence is ended either by a full stop, question mark or excalmation mark
a paragraph is ended by two consecutive new line charaters


this is what i have got so far::
#!c:\perl\bin\perl.exe
my $stats = "Statistics For File: \n";
chomp($stats);
my $chrs = "Characters: \n";
my $wds = "Words: \n";
my $lines = "Lines: \n";
my $snt = "Sentences: \n";
my $par = "Paragraphs: \n";
my $x;
enter:
{
print("Please enter a file name: ");
$ent = <STDIN>;
chomp($ent);

if($ent =~ m/(^\w{1,8})(\.txt?)$/)
{
open(READFILE, "$ent") || die "couldn't open file: $!";

}
elsif($ent =~ m/(^\w{1,8})$/)
{
open(READFILE, "$ent.txt") || die "couldn't open file: $!";
}
else
{
print("re-enter filename!\n");
redo enter;
}
}


i would really appreciate some help here, i have the general idea of what i have to do but getting it down in code is vexing me

PLEASE HELP





close(READFILE);
Reply With Quote