You can put whatever code you want between various when blocks. You can also have more than one default - a default is just a when with a condition that's always true:
my @test = qw [abc def ghi xyz jkl mno];
for (@test) {
say "Testing '$_'";
when (/abc/) {say " Got 'abc'"; continue}
say " After when /abc/";
when (/def/) {say " Got 'def'"; next;}
say " After when /def/";
when (/ghi/) {say " Got 'ghi'";}
say " After when /ghi/";
when (/jkl/) {say " Got 'jkl'"; last;}
say " After when /jkl/";
default {say " Default 1"; continue}
say " After first default";
default {say " Default 2";}
say " After second default"
}
continue {
say " Continue for '$_'";
}
__END__
Testing 'abc'
Got 'abc'
After when /abc/
After when /def/
After when /ghi/
After when /jkl/
Default 1
After first default
Default 2
Continue for 'abc'
Testing 'def'
After when /abc/
Got 'def'
Continue for 'def'
Testing 'ghi'
After when /abc/
After when /def/
Got 'ghi'
Continue for 'ghi'
Testing 'xyz'
After when /abc/
After when /def/
After when /ghi/
After when /jkl/
Default 1
After first default
Default 2
Continue for 'xyz'
Testing 'jkl'
After when /abc/
After when /def/
After when /ghi/
Got 'jkl'
|