On Mon Oct 14 11:45:54 2019, haarg wrote:
Show quoted text> I do have some slight concerns regarding the partial symmetry though.
> Given how foreach works, I would possibly expect it to work without
> the 'my'. This of course adds scoping nightmares. Luckily this could
> just be an error, so confusion should be minimal.
That `foreach` works without `my` by shadowing an existing (package) variable I expect is a historic baggage from the days of perl-before-5, when lexical variables didn't even exist. There's no reason we should copy that. I'm intending to allow only
catch { ... }
catch my $var { ... }
and anything else be a syntax error.
Show quoted text> Similarly, catch without a variable would seem to imply aliasing $_ to
> the error. This is rather ugly of course, but it would be my
> expectation. And it couldn't throw an error, since it wouldn't be
> invalid syntax.
>
> I don't think either of these are showstoppers, but they seem worth
> addressing, at least in the documentation.
The existing semantics would remain - that the error ends up in `$@` - because that is core perl's provided behaviour. That is indeed a documentation point, just to remind users that lacking a new lexical, the error will be in `$@` as usual. I especially don't want to get into the realm of copying the error also into `$_` because that would overwrite what may be a useful value from outside the `try` block.
--
Paul Evans