Paul Russell Paul Russell - 2 years ago 92
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/ 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 Source

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


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

After removing the trailing }:

$ perl -c syntax OK

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

           Should be "$i"
$ perl -c -e'for i ( ) { }'
Missing $ on loop variable at -e line 1.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download