|
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.
|