Executing Perl program on windows?

Nik

New member
I am learning here so If I make mistakes just notify me which may be a lot

When I check the file by issuing the

perl -c couter1.pl

command which checks the file counter1.pl for errors it says syntax ok

but when I run the program it finds an error which I think I understand
The code below is the problem code well just the line separated. the length one not the char one

while(<INFILE>) {
$TheLine = $_;
chomp($TheLine) ;
$LineCount = $LineCount + 1;

$LineLen = length($TheLine);

$CharCount = $CharCount + $LineLen;

The error I'm presented with is an undefined subroutine.
which points out the line I think it means I haven't declared a variable
the variable being the length one at the top where I declared the rest.
Like so is this the reason and how do I correct it if you want the full program I will copy and paste it in.
$CharCount = 0;
$WordCount = 0;
$LineCount = 0;

Any help is greatly appreciated.
 
add the following at the top of your program:

use strict;
use warnings;

That will give you better error messages. The solution to the problem you're describing is to DECLARE your variables with "my". Here is a more elegant version:

use strict;
use warnings;
my $iLines;
my $iChars;
...
while (my $sLine = <INFILE>)
{
chomp $sLine;
$iLines++;
$iChars += length $sLine;
}
 
Back
Top