Hi.
Has anyone managed to complete this perl tma, because still stuck on this and don`t understand what patterns to use as there are allways syntax errors ?, i`ve have studdied the book over an over agian but i still don`t get it all, plus it`s not explained probaly in the book
here`s what you have to do:
you are to write a program a that analyses text files to obtain statistics on their content.
The program should operate as follows:
1) When run, the program should check if an argument has been provided. If not, the program should prompt for, and accept input of, a filename from the keyboard.
2) The filename, either passed as an argument or input from the keyboard, should be checked to ensure it is in MS-DOS format. The filename part should be no longer than 8 characters and must begin with a letter or underscore character followed by up to 7 letters, digits or underscore characters. The file extension should be optional, but if given is should be ".TXT" (upper- or lowercase).
If no extension if given, ".TXT" should be added to the end of the filename. So, for example, if "testfile" is input as the filename, this should become "testfile.TXT". If "input.txt" is entered, this should remain unchanged.
3) If the filename provided is not of the correct format, the program should display a suitable error message and end at this point.
4) The program should then check to see if the file exists using the filename provided. If the file does not exist, a suitable error message should be displayed and the program should end at this point.
5) Next, if the file exists but the file is empty, again a suitable error message should be displayed and the program should end.
6) The file should be read and checked to display crude statistics on the number of characters, words, lines, sentences and paragraphs that are within the file.
and here`s help the tutor sent me:
if ($filename !~ m/ /i)
{
die("not valid.\n"); #more can be added here
}
# does the filename end with .TXT?
if ($filename !~ m/ /i)
{
$filename .= ".TXT";
}
###end code snippet###
Note how I have left blanks where patterns should be. Refer to page 3-6/3-7. Try this first and then try to answer points 4 & 5.
4) The program should then check to see if the file exists using the filename provided. If the file does not exist, a suitable error message should be displayed and the program should end at this point.
5) Next, if the file exists but the file is empty, again a suitable error message should be displayed and the program should end.
###Page 7-6 - Determining information about files###
### point 4)###
### check if filename is actual file, exit if not###
if ( )
{
die(" error "); #more can be added here
}
### point 5)###
### check if filename is empty, exit if it is###
if ( )
{
die(" error "); #more can be added here
}
###end code snippet###
Again, note how I have left blanks for the if conditions. Refer to Page 7-6 for more information.
6) The file should be read and checked to display crude statistics on the number of characters, words, lines, sentences and paragraphs that are within the file.
I will leave the remainder of the assignment for you to complete although here is an example on how to count sentences.
###Page 7-5 - The getc function###
###Page 2-3 - String Boolean expressions###
###Page 2-6 - The While Statement###
while ($ch = getc(READFILE))
{
# count sentences:
if ($ch eq "?" || $ch eq "!" || $ch eq ".")
# if character is one of the three end of sentence markers
{
$sentences++;
}
}
close(READFILE);
# display results
print("Sentences: $sentences\n");
###end code snippet###
what ive already done:
#!c:\perl\bin\perl.exe
if ($#ARGV == -1)
{
print("Enter filename: ");
$filename = <STDIN>;
chomp($filename);
}
else
{
$filename = $ARGV[0];
}
if ($filename !~ m/\.TXT)
die("not valid.\n");
}if ($filename !~ m/\.txt/)
{
$filename .= "testfile.txt";
}
if (-r $filename && -w $filename)
{
die(" error ");
}
if (-e)
{
die(" error ");
}
while ($ch = getc(READFILE))
{
if ($ch eq "?" || $ch eq "!" || $ch eq ".")
{
$sentences++;
}
}
close(READFILE);
print("Sentences: $sentences\n");
can anyone help ?

s