📘 Prefix operator let in Perl 6

📘 Prefix operator let in Raku

N. B. Perl 6 has been renamed to Raku. Click to read more.


let is a prefix operator, which is similar to temp, but works correctly with exceptions. The previous value of the variable will be restored if the scope was left because of the exception.

my $var = 'a';
try {
    let $var = 'b';
    die;
}
say $var; # a

With a die, this example code will print the initial value a. If you comment out the call of a die, the effect of the assignment to b will stay, and the variable will contain the value b after the try block.

The let keyword looks similar to the declarators like my and our, but it is a prefix operator.

Leave a Reply