Variables & sigils

The match & error variables $/ and $!

Full

Two 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
oops

Notes #