September 2017
Beginner
402 pages
9h 52m
English
The let operator sets a new value for the variable. The key feature of it is the ability to restore the original value if the code block fails.
Consider the following example. The $var variable is set to a new value inside the code block between the pair of curly braces. The variable is printed after the end of the block. As there are no exceptions, the program prints the new value—2, as shown here:
my $var = 1;{ let $var = 2;}say $var; # 2
If the block, for some reason, dies, then the variable will keep the original value. The exception caused by die is caught by the CATCH block. The new value, 2 is then lost, and the program prints 1, as you can see here:
my $var = 1;try { let $var = 2; die;}CATCH {}say $var; # 2
The ...