User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 429,841 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,831 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums

PERL Text Statistic Help

Join Date: May 2008
Posts: 3
Reputation: designblocks is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
designblocks designblocks is offline Offline
Newbie Poster

PERL Text Statistic Help

  #1  
May 15th, 2008
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:
  1. Characters
  2. Words
  3. Lines
  4. Sentences
  5. 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!
Attached Files
File Type: txt perl program.txt (302 Bytes, 4 views)
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 6:29 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC