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 423,815 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 3,814 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

Re: PERL Text Statistic Help

  #3  
May 16th, 2008
Originally Posted by KevinADC View Post
Be more specific, what part do you need help with? It looks like you have the general idea of how to do the assignment although there might be better ways to code it, that is not important right now. Learning is incremental, you will learn better methods as you go.

What is unfortunate is that that you are not using "strict" or "warnings", so the quality of your perl course is in question.



It's not a perl course but you are right my course is only basic so I'm not to fused really. The code has been updated to the following:

#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";
}

if (-e $filename)
{
die("File does not exist\n");
}

if (-s $filename)
{
die("File is empty\n");
}

while ($ch = getc(READFILE))
{
if ($ch eq "?" || $ch eq "!" || $ch eq ".")
{
 $sentences++;
}
}

close(READFILE);

print("Sentences:    $sentences\n");

I only need help with the part of code in bold type. I now need to display statistics about the number of words, characters and paragraphs.

I think I need a separate while statement for each of the additional code for this script to be complete.

PLEASE HELP WITH:
  1. How do I get the program to understand that I need it to count every character, including white spaces?
  2. How can I get it to count the number of individual words?
  3. How do I get program to count the paragraphs?

I know a \n means a new line and that the last item on the above list uses this to count paragraphs but how do I code that?

Really getting a brain ache!
Reply With Quote  
All times are GMT -4. The time now is 3:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC