in reply to Re: Why doesn't exist work with hash slices?
in thread Why doesn't exist work with hash slices?

> exists @haystack{qw(aa bb cc dd)} should provide an "ANY" test. Some might think an "ALL" test would be correct.

In order to respect orthogonality to delete I'd expect a _list_¹ of booleans to be returned.

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

¹) emphasize updated

  • Comment on Re^2: Why doesn't exist work with hash slices?

Replies are listed 'Best First'.
Re^3: Why doesn't exist work with hash slices?
by Anonymous Monk on Sep 21, 2025 at 13:22 UTC

    According to perldoc -f delete, it returns the deleted value, not a Boolean. And,

    $ perl -E 'my %foo = qw{ bar 42 }; say delete $foo{bar};'
    

    in fact prints 42.

      LanX isn't saying that delete ELEMENT returns a boolean; they're saying that since delete SLICE returns a list of what it would return for a single element (the deleted element), exists SLICE should also return a list of what it return for a single element (a boolean).

      Delete returns the deleted value*s* (plural) of a slice and you didn't test a slice. ¹

      Exists returns an (informal) Boolean (1 or dualvar ""/0) for a hash entry, and logically should also return a list of booleans in case of a slice.

      Cheers Rolf

      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery

      Edit

      ¹) From the docs of delete I already linked to

      my %hash = (foo => 11, bar => 22, baz => 33); my $scalar = delete $hash{foo}; # $scalar is 11 $scalar = delete @hash{qw(foo bar)}; # $scalar is 22 my @array = delete @hash{qw(foo baz)}; # @array is (undef,33) <--- H +ERE
        And if given a key value slice, delete returns a list of key value pairs of what was deleted from the hash. Not clear what a corresponding exists feature would do.