HI ALL
thanks for all ur help. but now it takes mulitple files but the result is not correctly coming
the code i have used is
# count characters, words and lines in two files
- use strict;
-
my $chars = 0;
-
my $words = 0;
-
my $lines = 0;
-
my ($token,@tokens);
-
my ($file,@files);
-
sub tokenize {
-
$_ = $_[0];
-
s/\s+/\n/g;
-
s/^\n//;
-
s/$/\n/;
-
s/([.,!?:;,])\n/\n$1\n/g;
-
s/\n(["'`])([^\n])/\n$1\n$2/g;
-
s/([^\n])(["'`])\n/$1\n$2\n/g;
-
s/([^\n])([.,])\n/$1\n$2\n/g;
-
s/\n([A-Z])\n\./\n$1./g;
-
s/\n\.\n([^"A-Z])/\.\n$1/g;
-
s/(\.[A-Z]+)\n\.\n/$1.\n/g;
-
s/([^\n])'s\n/$1\n's\n/g;
-
s/([^\n])n't\n/$1\nn't\n/g;
-
s/([^\n])'re\n/$1\n're\n/g;
-
s/\n\$([^\n])/\n\$\n$1/g;
-
s/([^\n])%\n/$1\n%\n/g;
-
s/Mr\n\.\n/Mr.\n/g;
-
return(split(/\n/,$_));
-
}
-
-
@ARGV = qw("ApacheLFAsample.log","apache.txt" );
-
foreach $file (@ARGV)
-
{
-
$chars += length;
-
@tokens = &tokenize($_);
-
foreach $token (@tokens)
-
{
-
if ($token =~ /[a-zA-Z]/) { $words++; }
-
}
-
$lines++;
-
}
-
print "Found $lines lines, $words words and $chars characters.\n";
-
exit(0);
The thing i want here is the csript should read both files and should tell the number of lines,chars etc corresponding to each file
the output am getting now does not even match with a single file contents
expecting some help
thanks to whatever help i get
sunil