"geek" <> wrote in
news: oups.com:
> I am getting this error
which error?
> in my perl script at the line "else {stat()
"
> See the code at the bottom
....
> if( param('Get')){ date();}
> else { stat();}
Please post a short but complete script that others can easily run.
> sub stat {
perldoc -f stat
What, oh what, is the purpose of using the name of a perl built-in?
> print header(), start_html("The Statistics for Administrator");
> open(fileHandle,"./outputFile") or die "The file cannot be opened";
Why is the input file called "outputFile"?
Do include the reason for the failure as well as the name of the file in
your error messages.
> my @fileData = <fileHandle>;
There is no need to slurp the file if you are going to process it line-
by-line anyway.
> my $count1=0;
> my $count2=0;
> my $count3=0;
> my $count4=0;
> my $count5=0;
> my $count6=0;
> my $count7=0;
> my $count8=0;
> my $count9=0;
> my $countt=0;
> my @array;
Whenever you find yourself writing tedious stuff like this, please take
a moment to actually think about the problem you are attempting to
solve.
You have provided no information on the format of the data you are
trying to process, so it is really hard to figure out what you are
trying to do, but I suspect the following noise
> foreach my $word(@fileData){
> @array=split(/ /, $word);
> foreach my $element(@array){
> if($element eq "CS5375"){
> $count1++;
> }
> if($element eq "cd"){
> $count2++;
> }
> if($element eq "cp"){
> $count3++;
> }
> if($element eq "vim"){
> $count4++;
> }
> if($element eq "%ls-l"){
> $count5++;
> }
> if($element eq "man"){
> $count6++;
> }
> if($element eq "perl-v"){
> $count7++;
> }
> if($element eq "all"){
> $count8++;
> }
> if($element eq "finger"){
> $count9++;
> }
> if($element eq "ftp\n"){
> $countt++;
> # print "hello";
> }
can be replaced with:
#! /usr/bin/perl
use strict;
use warnings;
sub calc_stats {
my $filename = shift;
open my $fh, '<', $filename
or die "Cannot open $filename: $!";
my %stats;
while(my $line = <$fh>) {
my @words = split / /, $line;
++$stats{$_} for @words;
}
return \%stats;
}
use Data:

umper;
print Dumper(calc_stats('outputFile'));
__END__
It is now up to you to fix the rest of the jumble. In the process, you
might also discover what "this" error is. "Use of uninitialized value"
is a warning, not an error. It is too tedious to try and figure out
which part of your code is causing the warning to be emitted.
> my $noLine;
> open( fileHandle,"<./outputFile");
> $noLine++ while <fileHandle>;
What is the purpose of opening the same file again (especially since you
have not closed it yet, to re-read it in its entirety. I have a sneaking
suspicion (which I cannot be bothered to test, but you should) that no
lines are being read from the file as it is at EOF now. Hence $noLine is
uninitialized etc.
Have you read the posting guidelines for this group?
Sinan