in reply to given/when one case prefixes another

without goto and given/when

Bare blocks are internally one-time while-loops allowing continue-blocks (see perlsyn)

for ("a".."c"){ { print && next if /a/; print && next if /b/; # here neither a nor b last; # skip continue-block } continue { # here either a or b print " is in group1"; } print "\n" # all }

your free to have more blocks or combining with elseifs or LABEL:s.

Cheers Rolf

UPDATE:

or without fall-through

for ("a".."c"){ { if ( /a/ ) { print } elsif ( /b/ ) { print } else { last } print " is in group"; # a,b } print "\n" # all }

See also: Re^3: given/when one case prefixes another

Replies are listed 'Best First'.
Re^2: given/when one case prefixes another
by John M. Dlugosz (Monsignor) on Apr 27, 2011 at 11:26 UTC
    I see: there are advantages to using if statements instead of when's. I'll keep that in mind.