in reply to Re: Question about loops and breaking out of them properly (updated)
in thread Question about loops and breaking out of them properly

Another efficiency possibility would be to use a hash and exists (or treat it as a set where keys for members get set to 1). Precaffeine at the moment (so I believe this was the intent but not sure) but for what the op was trying setup a %valid_selections and then loop over the values passed setting $selected{$item} = 1 if exists $valid_selection{$item} then @selection = keys %selected.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^3: Question about loops and breaking out of them properly
by unmatched (Sexton) on Apr 19, 2025 at 09:54 UTC

    Hi, and thank you for your feedback

    You're correct, I'm basically trying to recreate a list of some sort that I can iterate over later. I considered using a hash for this but in this case it's such a short list that it's probably faster to do this with a list.

    I realized later that I want to check the final list for duplicates, which I've fixed with the List::Util::uniq function (using this module is already paying off!). It adds an extra iteration over the final list but again, quite small in size, otherwise I would've also preferred to use a hash.