Hello and welcome to CertForums.co.uk, here we host free active certification forums with links to the best free resources for Microsoft's MCSA MCSE MCDBA Cisco's CCNA CCDA and CCNP, and CompTIA's A+ Network+ i-NET+ and Security+ certifications in the UK. If you wish to post or use other advanced features you will need to register first. Registration is absolutely free and takes only a few minutes to complete so sign up today!

If you have any problems with the registration process or your account login, please contact support

Go Back   CertForums > Computing Support Forums > Programming & Scripting
Home Forums Register Search Today's Posts Mark Forums Read

Perl Section 2B TMA 10 help ?

Post New ThreadReply
 
Thread Tools Display Modes
  #1  
Old 28-Apr-2008, 04:48 PM
brummyneil brummyneil is offline
New Member
Posts: 1
Points: 0 brummyneil has no points
Power: 1
None
Join Date: 28 Apr 2008
Perl Section 2B TMA 10 help ?

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


Last edited by brummyneil : 29-Apr-2008 at 12:10 PM.
 
Reply With Quote
  #2  
Old 28-Apr-2008, 06:40 PM
hbroomhall hbroomhall is offline
Premium Member
Posts: 6,276
Points: 2130 hbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 points
Power: 89
None
Join Date: 08 Sep 2005
Location: Tunbridge Wells, Kent
Certifications: ECDL A+ Network+ i-Net+
WIP: Server+
Um - where to start!

1) Check the braces - they don't match up.
2) The first match test is missing any indication of where the match string ends.
3) The -e operator takes a filename to operate on. But it is redundant here as you have already tested for the file being readable.
4) You aren't opening the file, so READFILE is undefined.

The TMAs seem to change over time, so I can only guess what the question is.

Oh, and welcome to CF!

Harry.

 
Reply With Quote
  #3  
Old 23-Jun-2008, 11:32 AM
Davo1977 Davo1977 is offline
New Member
Posts: 5
Points: 0 Davo1977 has no points
Power: 1
None
Join Date: 23 Jun 2008
Location: BEXHILL
WIP: CIW Website Design Manager
I need to analyse a text file to obtain statistics on its contents? It should check if an argument has been provided and if not, it should prompt for, and accept input of a filename from the keyboard. This filename should also be checked to ensure it is in MS-DOS format and should be no longer than 8 characters. The file extension should be optional but if it is given then it should be .txt, either upper or lowercase. If an extension isn't given, .TXT should be added to the end of the filename. If the filename provided isn't the right format the program should display a suitable error message and end at this point. It should then check to see if the file exists using the filename given. If it doesn't then the error message should again be displayed then ended again. If the file does exist but it's empty the error message again to be displayed then ended. If the file exists and contains words or characters etc. it 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 am struggling with this assignment as i feel the course notes are simply not good enough. thompsonelvis@aol.com

 
Reply With Quote
  #4  
Old 23-Jun-2008, 06:49 PM
hbroomhall hbroomhall is offline
Premium Member
Posts: 6,276
Points: 2130 hbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 points
Power: 89
None
Join Date: 08 Sep 2005
Location: Tunbridge Wells, Kent
Certifications: ECDL A+ Network+ i-Net+
WIP: Server+
I've commented on this in the thread you started.

Harry.

 
Reply With Quote
  #5  
Old 30-Jun-2008, 07:39 AM
Davo1977 Davo1977 is offline
New Member
Posts: 5
Points: 0 Davo1977 has no points
Power: 1
None
Join Date: 23 Jun 2008
Location: BEXHILL
WIP: CIW Website Design Manager
Analysing character, paragraphs, lines, words counts in text files using perl

Here is some code which answers questions 1-5.
Does anybody have any suggestions which tackles the following question 6 Below: -

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 fie.
- the character count can include any whitespaces and punctutaion characters (i.e. it can include all
characters in the file)
- each sentence is ended by either a full stop, question mark or exclamation mark.

Code so far -

#/usr/bin/perl/

use strict;
use warnings;

if ($#ARGV == -1)
{
print("Please Enter Filename: ");
$filename = <STDIN>;
print("Statistics for $filename");
chomp($filename);
}
else
{
$filename = $ARGV[0];
}
if (!-e $filename)
{
die("File does not exist\n");
}
if (!-s $filename)
{
die("File is empty\n");
}
open(READFILE, "<$filename") or die "Can't open file \"$filename\":$!";
while(<READFILE>)
{

 
Reply With Quote
  #6  
Old 30-Jun-2008, 09:25 AM
hbroomhall hbroomhall is offline
Premium Member
Posts: 6,276
Points: 2130 hbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 points
Power: 89
None
Join Date: 08 Sep 2005
Location: Tunbridge Wells, Kent
Certifications: ECDL A+ Network+ i-Net+
WIP: Server+
Quote:
Originally Posted by Davo1977 View Post
Here is some code which answers questions 1-5.
Actually it misses quite a lot of the requirements of 1-5.

Why not continue this in the thread you started?

Harry.

 
Reply With Quote
Post New ThreadReply Spread this thread: Submit this thread to digg Submit this thread to del.icio.us


Go Back   CertForums > Computing Support Forums > Programming & Scripting


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passed Perl stuPeas CIW Certifications 10 01-Apr-2008 08:35 AM
Simple perl question? Simple advice please dee1810 Programming & Scripting 12 02-Oct-2007 02:00 PM
CIW Design TMA 11; section 2 part B, web languages-PERL CAMBA New Members Introduction 8 31-May-2007 12:54 AM
CIW: TMA 11- HELP!! HONESTLY.- CAMBA CIW Certifications 1 30-May-2007 04:24 PM
Perl Course at Home the1stefan Programming & Scripting 8 21-Apr-2007 03:15 PM


All times are GMT. The time now is 04:50 AM.

Powered by vBulletin® Version 3.6.11
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
CertForums.co.uk (C) copyright 2003-2007 All Rights Reserved. Content published on CertForums.co.uk requires permission for reprint.
Hosted by Lunarpages