Short-circuited Perl grep


/ Published in: Perl
Save to your folder(s)

To check the existence of an element in a Perl array with specific properties, one tends to use `grep`. But this is inefficient because `grep` always checks each element. (Even in scalar context it returns the number of matching elements.) The following function aborts after the first find.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.