http://qs321.pair.com?node_id=1202206


in reply to Re^6: Anagrams & Letter Banks
in thread Anagrams & Letter Banks

Thank you, Laurent_R. If it is the case that grep outputs the values themselves that are true, how is it that the  next unless grep !/(.).*\1/, @list;line appears to be doing what I want it to in this:
for (sort keys %words) { my @list = sort @{$words{$_}}; next unless @list > 1; next unless grep !/(.).*\1/, @list; print "@list\n";
If grep outputs the words themselves, why is the "next unless" part working?

Replies are listed 'Best First'.
Re^8: Anagrams & Letter Banks
by Cristoforo (Curate) on Oct 27, 2017 at 22:23 UTC
    If grep outputs the words themselves, why is the "next unless" part working?
    In list context, grep will output the words, but in scalar context, (here forced by 'unless'), grep will return the number (0 1 2 ...) of times the condition it is testing is true.

    In this code, if grep tests a word composed of unique letters, the regex test will fail and applying the negation (!), forms a double negative which is equal to true. Here grep returns 1, (or 2 or more depending how many words are made up of unique letters in @list).