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

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

Thread Previous
From:
=?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?=
Date:
August 19, 2021 23:05
Subject:
Re: defined $a, where $a is actually a HASH
Message ID:
87v941ujfl.fsf@wibble.ilmari.org
David Nicol <davidnicol@gmail.com> writes:

>> :    These have been unreachable since `defined @array` and `defined %hash`
>> :    became syntax errors.
>>
>
>
> looks like I missed several meetings. I still expect
>
>     no strict;
>     print (defined(@arr) ? 1 : 2);
>     @arr = (1);
>     print (defined(@arr) ? 1 : 2);
>     print (defined(%h) ? 1 : 2);
>     %h = (1,2);
>     print (defined(%h) ? 1 : 2);
>     print "\n";
>
> to print 2121.

That's been deprecated since 5.6:

https://perldoc.perl.org/perl56delta#defined(@array)-is-deprecated

and became a syntax error in 5.22:

https://perldoc.perl.org/perl5220delta#defined(@array)-and-defined(%25hash)-are-now-fatal-errors

> I have apparently never needed to do that, but the new thing is something
> like *h->{HASH}, right?

What new thing?

The thing Nicholas mentioned breaking is XS code storing a hash or array
(PVHV or PVAV), not a reference to one (an IV with SVf_ROK), in a scalar
variable, and then doing defined($foo), which is not a valid thing to do.

- ilmari

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About