Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Whats wrong with using grep in a void context?

context GREP void wrong
0
Posted

Whats wrong with using grep in a void context?

0

The problem is that grep builds a return list, regardless of the context. This means you’re making Perl go to the trouble of building a list that you then just throw away. If the list is large, you waste both time and space. If your intent is to iterate over the list, then use a for loop for this purpose. In perls older than 5.8.1, map suffers from this problem as well. But since 5.8.1, this has been fixed, and map is context aware – in void context, no lists are constructed.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.