in reply to Re^5: Using exists to check element in array
in thread Using exists to check element in array
> ( grep { !exists( $a[$_] ) } keys @a ) ? "can" : "didn\x27t" );
Looks like keys @array was added to Perl in 5.12
And it's obviously inconsistent to delete and exists .
> The very existence of this inconsistency is reason enough for a warning.
But it's even worse!!!
keys is inconsistent to the behavior in hashes, even without using delete and exists and ever seeing any warnings !!!
my (@y,%y); $y[3]=$y{3}=1; say "keys \%y: ", join ",",keys %y; say "keys \@y: ", join ",",keys @y;
-->
keys %y: 3 keys @y: 0,1,2,3
A consistent implementation of keys ARRAY should check with exists first before returning an index.
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Using exists to check element in array
by ikegami (Patriarch) on Feb 01, 2024 at 17:32 UTC | |
by ikegami (Patriarch) on Feb 01, 2024 at 18:04 UTC | |
by LanX (Saint) on Feb 03, 2024 at 21:55 UTC | |
by ikegami (Patriarch) on Feb 04, 2024 at 03:39 UTC |