📘 Prefix operator let in Perl 6

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s