I'm new to perl so please bear with me.
I have script that is parsing a CSV file. To make things easier to debug I am using a state machine FSA::Rules (works great love it).
Every thing is going well only now I need to make my logs make sense, as part of this I need to record line numbers so my program looks some thing like this.
my $line = '';
my $lineCount = 0;
sub do {
...
#CSV opened
...
#State machine stuff happens here
readLine;
if ($line =~ m/.*Pattern*/){
#do stuff
}
}
sub readLine{
$line = <CSV>;
$lineCount ++;
}
But I get the following error
Use of uninitialized value $line in pattern match (m//) at
Any one know why $line would not be initialized? Thanks.
do, and you shouldn't name a subroutine the same as a reserved word as, for one thing, it's very awkward to call. Please show the code that fails. Do you declaremy $lineagain insidesub do?use strict;anduse warnings;after the #! line (which should be the first line of the script).#!line isn't necessary or even desirable (although strict and warnings are!)/usr/bin/perl" in front of it.