I was just reading the documentation on grep. I'm familiar with using grep in the Terminal simply to find matches using regular expressions. I am less familiar with how grep behaves in Perl. I just added a line of code to the script I'm working on for the letter banks, and it appears to be doing exactly what I need it to. But I think it would only work if somehow the grep were returning true or false (as opposed to returning the actual string which is a match (or non-match)).
for (sort keys %words) {
my @list = sort @{$words{$_}};
next unless @list > 1;
next unless grep !/(.).*\1/, @list;
print "@list\n";
I'm trying to print @list only if it contains more than one element, AND it has at least one element which contains no repeat letters. This seems to be working, but again, as I see it, the grep command must be returning true or false for it to work. | [reply] [Watch: Dir/Any] [d/l] |
| [reply] [Watch: Dir/Any] |
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?
| [reply] [Watch: Dir/Any] [d/l] [select] |