View Single Post
  #3 (permalink)  
Old Aug 9th, 2007, 18:14
DPhahn DPhahn is offline
Junior Member
Join Date: Aug 2007
Location: chesterfield
Age: 37
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Understadning Perl Basics

OR this..yu missed the backslash before .txt...if ($file !~ m/.txt$/)
it should be if ($file !~ m/\.txt$/)
Code: Select all
my ($lastchar,$lines,$file,$paragraphs,$ch);
print("enter filename: ");
my $file = <STDIN>;
chomp($file);
if ($file !~ m/\.txt$/)
{
$file .= ".txt";
} 
open(READFILE, "$file") || die "No File Found";
my $i = 1;
while ($ch = getc(READFILE))
{
if ($ch eq "\n") # if newline...
 {
  $lines++; # count another line
  if ($lastchar eq "\n") # if last character also newline
  {
  $paragraphs++; # count another paragraph
  }
 }
}
print ("There are " . $i . " Lines in " . $file);
close(READFILE);

Last edited by karinne; Aug 9th, 2007 at 18:16. Reason: Again ... please use [ code ]...[ /code ] tags when displaying code.
Reply With Quote