Hello perlancar,
Tangential observation:
push @ary, "foo" unless grep { $_ eq "foo" } @ary;
I think either the any or the none function in the core List::Util module would be better than grep in this case:
push @ary, "foo" unless any { $_ eq "foo" } @ary; # OR push @ary, "foo" if none { $_ eq "foo" } @ary;
Not only are these clearer (since the reader doesn’t have to work out “what is grep returning here?”), but they’re also more efficient because — unlike grep — they short-circuit as soon as a match is found.
Hope that’s of interest,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: "Useless use of a constant" in grep block?
by Athanasius
in thread "Useless use of a constant" in grep block?
by perlancar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |