in reply to Sparing multiple 'or's

I'm presuming you intended string rather than numeric comparisons (so $a eq 'ABA'). In which case this does it:
if ($a =~ /^ ( ABA | SCO | ACC | PHC | GHF ) $/x ) { ... }

Dave.

Replies are listed 'Best First'.
Re^2: Sparing multiple 'or's
by jimpudar (Pilgrim) on Jun 04, 2018 at 18:47 UTC

    This is how I would do it, but I generally use a non-capturing group whenever possible for clarity:

    if ( $a =~ /^ (?: ABA | SCO | ACC | PHC | GHF ) $/x ) { ... }

    Note that this is more for capturing intent than performance. When I see a capture group (...), I assume we will be using whatever was captured. In this case, since we are capturing the entire string, $a == $1.

    Probably not worth the nitpick :)

    Best,

    Jim

    πάντων χρημάτων μέτρον έστιν άνθρωπος.