When I run this:
use feature ':5.10';
$x=1;
given ($x) {
when(1) {
say '1';
$x = 2;
continue;
}
when (2) {
say '2';
}
}
This should print both 1 and 2, but it only prints 1. Am I missing something?
EDIT:
I have added $x = 2 and it still prints only "1"
See the perlsyn man page:
given(EXPR) will assign the value of EXPR to $_ within the lexical scope of the block
This code outputs 1 and 2:
use feature ':5.10';
$x=1;
given ($x) {
when(1) {
say '1';
$_ = 2;
continue;
}
when (2) {
say '2';
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With