/* Test for various pattern matching operators*/ /* Test that the match argument is valid in a procedure called * while a match is open */ proc winner() { "Mondo ", ?1, "!\n"; } proc main() { var s = L"Di\x0394 we win?"; /* Execute the match statement. The first match is the one * executed. */ match (s) { case "(w.n)" : say(?1, "!\n"); winner(); case "win" : "We should not be here!\n"; default : "No match.\n"; } /* Execute the match operator */ if (s ~= "lose|win") { "We won again!\n"; } else { "We definitely lost.\n"; } /* Verify the case of the match operator which does not match */ if (s ~= "epic|fail") { "Epic fail!\n"; } /* Verify that the match argument is invalid when a match statement * is not active */ try { s = ?1; } catch( e ) { "Still winning - caught exception (as expected)\n"; } }