in reply to Re: Logical/defined or as lvalue
in thread Logical/defined or as lvalue

When would it be useful?

Consider items from @list to be counted, with one "given" set and a "rest". A pre-initialized hash %h1 holds the "given" set and an empty hash %h2 counts the rest. Then we could:

${\($h1{$_} // ($h2{$_} //= 0))}++ for @list;

Greetings,
🐻

$gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

Replies are listed 'Best First'.
Re^3: Logical/defined or as lvalue
by ikegami (Patriarch) on Sep 03, 2024 at 20:25 UTC

    If you're going to count them all, I don't see the point of having the counts split across two hashes. If there's an important distinction between the two sets of strings, you would need those lists, and you could access the counts of either lists.

Re^3: Logical/defined or as lvalue
by LanX (Saint) on Sep 03, 2024 at 20:45 UTC
    If I wanted to do this, I'd count only in one hash and use a hash-slice to extract the "given" ones.

    Less code and more flexible.

    Update

    Alternatively a HoH where the first key decides what is given or rest.

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