πŸ“˜ 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

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code