I have been working on an assignment for a while now and I have had many problems making the program work from the information and help supplied by my course.
The program I need to make is one that analyses text files to obtain statistics on their content.
The following rules apply:
1) When run, the program should check if an argument has been provided. If not, the program should prompt for, and accept input for, 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 it should be ".TXT" (upper or lowercase). For example:
If no extension given .TXT should be added to the end of the filename.
3) If filename provided is not correct format an error message message should appear and the program exits.
4) Program should check to see if filename supplied exists and if not error message displays and program exits.
5) If file exists but file is empty (i.e. no data) an error message must display and program exits.
6) The file must be read and checked to display crude statistics on the number of:
- Characters
- Words
- Lines
- Sentences
- Paragraphs
For a non perl programmer like myself I have managed to code some of the program to a satisfactory level, see below:
#usr/bin/perl
if ($#ARGV == -1)
{
print("Please enter a filename: ");
$filename = <STDIN>;
chomp($filename);
}
else
{
$filename = $ARGV[0];
}
if ($filename !~ m/[a-zA-Z]{0,7}\.TXT$/i)
{
die("File format not valid\n");)
}
if ($filename !~ m/\.TXT$/i)
{
$filename .= ".TXT";
}
(See attached file for the perl code I have made so far, if the above is unreadable.)
I really need help. I have made a hard effort to get this far and so want to finish this as I never give up on anything!!
Thanks!