It appears highly likely that you have a non-matching part of
the regex that results in an undefined value some of the time.
I would use something like code below to debug things. This assigns
all of the individual var names into one array (@result) and avoids a mess with
specifying each var name.
Run this on your data set and you see what it matching and what is not. Undefined is a
"value" and I don't think that just checking scalar @result is enough. Anyway this
should show where the program is failing to match, presumably on line 14 of
the input.
my @result = # note @ variable not $variable !!
(($beginning, $agency, $district, $ssn, $serv_per_m,
$serv_per_y, $serv_per_t,.............);
while (<IN>)
{
print;
my @result = (.....blah) #see previous posters code
my $token_nr=0;
foreach my $token (@result)
{
$token_nr++;
if (defined ($token) ) #if you try to print an undef
{ #program will bomb
print "$token_nr++\t$token\n"; #this allows you to see exact
+ly
} #what is undef without progra
+m
else #bombing
{
print "$token_nr++\tUNDEFINED\n";
}
}
}
I suspect that your regex is too restrictive. Also fixed column
files aren't that common but you may indeed have one. (\D) matches exactly one non-digit
charater, to allow say somewhere between 1 and 4 non-digit characters, use
(\D{1,4}).
for a character set, use say
([\d-]{9,11})
if ssn could be either 123-45-6789 or 123456789. Use \s* to indidicate zero or more space characters.