On 27 Jan 2016 7:15 AM, Moritz Lenz wrote:
On 01/27/2016 07:17 AM, Felipe Gasper wrote:
Hello,
What is the purpose of having $! in Perl 6?
The global variables in Perl 5 are a constant headache, prompting
us to need to local()ize variables like $@, $!, and $? to avoid
unforeseen consequences like RT #127386 and those documented in
Try::Tiny’s POD.
Perl 6 seems to give us both the “right” and the “wrong” solution
to accessing exception variables: we get $_ within a CATCH block
(right), but we also get that global $!--which, to me, seems
pathologically wrong.
But it's not global! None of $_, $/, $! are global.
I modified the example I posted before to test that:
---------------
use v6;
my $x = 10;
my $y = 0;
my $z = $x / $y;
my $exception;
{
{
say $z;
CATCH {
default {
$exception = $_;
}
}
}
}
if ($exception) {
say "There was an exception: $exception ($!)";
}
say "still running";
---------------
If you run this, $! is populated even when we’ve gone back a block level
from where the exception was thrown.
So, what *is* the scoping of $!?
-FG