develooper Front page | perl.perl5.porters | Postings from August 2021

Re: defined $a, where $a is actually a HASH

Thread Previous | Thread Next
August 19, 2021 17:00
Re: defined $a, where $a is actually a HASH
Message ID:
Nicholas Clark <> wrote:
:The summary - I think that this change is correct and should stay.
:The details - I did this. It's in blead. The commit message explains the
:reasoning. The code removed is deadweight, and likely contains 2 (more)
:branches, which are one of the banes of performant code:
:    These have been unreachable since `defined @array` and `defined %hash`
:    became syntax errors.

I think it would be wise to have an assert under DEBUGGING, especially
since you have already discovered that they have _not_ been unreachable.

:    Whilst the same PP code is used for // and //=,
:    expressions such as`@a // @b` put the left array (or hash) in scalar
:    context, meaning that it always returns a define value.
:    (Should we warn on these?)

If C<defined(@a)> is a syntax error, then I think C<@a // @b> should
be too: I feel C<A // B> should as far as possible be identical to
C<defined(A) ? A : B> except for the double-evaluation of A.

Even better would be making C<@a || @b> equivalent to C<@a ? @a : @b>)
(even in list context), and parallel-ly C<@a && @b> to C<!@a ? @a : @b>.

@neilb: this probably belongs in the ongoing PSC quirks discussion,
if it isn't already there.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About