Comparing Multiple Strings In Perl

后端 未结 5 1638
广开言路
广开言路 2021-01-17 23:15

I have my code like this:

if ( $var eq \"str1\" || $var eq \"str2\" || $var eq \"str3\" )
{
...
}

Is there anyways to optimize this. I want

5条回答
  •  孤城傲影
    2021-01-17 23:53

    I'm semi-joking, but this will do it:

    use Quantum::Superpositions;
    
    if ($x == any($a, $b, $c)) { ...  }
    

    See also this Perl Monks thread

提交回复
热议问题