Paul Russell Paul Russell - 7 months ago 26
Perl Question

Getting error for missing loop variable in perl

This is the exact error I am receiving:


Missing $ on loop variable at /local/home/parussel/workplace/sb_workspace/build/SwitchBuilder-2.0/RHEL5_64/DEV.STD.PTHREAD/build/private/perl5.8/blib//Error/ErrorNew.pm line 17.


This is the code here, but I can't see where the error is occurring.

# check required arguments...
foreach my $key ( @{ $self->{context} } ) {
die "$key is required" unless exists $args{$key};

# ... and take the ones we need
$self->{args}->{$key} = $args{$key}; # this could have a setter
}

return bless $self, $class;
}

Answer

The code you posted does not produce the error you posted.

As-is:

$ perl -c a.pl
Unmatched right curly bracket at a.pl line 10, at end of line
syntax error at a.pl line 10, near "}"
a.pl had compilation errors.

After removing the trailing }:

$ perl -c a.pl
a.pl syntax OK

You get the error you said you received from code such as the following:

           Should be "$i"
                 |
                 v
$ perl -c -e'for i ( ) { }'
Missing $ on loop variable at -e line 1.