Home > Software design >  Perl compilation problem that Perl::Critic does not see
Perl compilation problem that Perl::Critic does not see

Time:04-24

I have this if statement that does not pass compilation:

        my $string_var;
        if ( $string_var eq "string_value1" || $string_var eq "string_value2" ) &&
           (defined $ENV{VAR_NAME}) {
                die { "error_message" => "error_message" }
        }

Neither I nor Perl::Critic see a problem. But Perl says:

syntax error at /opt/app_protect/bin/../lib/perl/F5/BdCfg/Bundle.pm line 178, near ") &&"
syntax error at /opt/app_protect/bin/../lib/perl/F5/BdCfg/Bundle.pm line 181, near "}"

Can anyone help?

It's CentOS 7.6.1810 with Perl v5.16.3

CodePudding user response:

From perlsyn:

The following compound statements may be used to control flow:
...
if (EXPR) BLOCK

What you provide here is not

if (EXPR) BLOCK

but instead

if (EXPR1) && (EXPR2) BLOCK

This needs to be enclosed in parentheses in order to be a valid syntax, i.e.

if ((EXPR1) && (EXPR2)) BLOCK
  •  Tags:  
  • perl
  • Related