Variables & sigils
The match & error variables $/ and $!
FullTwo special variables Raku sets for you — the last regex match and the last error.
Two special lexical variables are populated automatically: $/ holds the most recent regex match, and $! holds the most recently caught exception. The capture shortcuts and error handling both read from them.
$/ — the match #
A successful ~~ against a regex sets $/. The positional captures $0, $1, … are shortcuts into it ($0 is $/[0]).
"abc123def" ~~ /(\d+)/; say ~$/; say ~$0;
Output
123
123$! — the error #
Inside (or after) a failed try, $! holds the exception, whose .message is its text.
try { die "oops" }
say $!.message;
Output
oopsNotes #
$/is why$0/$<name>work anywhere after a match — they don't need to be in theifthat did the matching, just in the same scope.- Both are ordinary lexicals, so their value is scoped to the current routine/block; a nested match sets its own
$/. - After a successful
try,$!is reset to an undefined value, so$!.definedis a clean "did the last try fail?" test.