Yes, it isn't that hard to write one. But you missed one aspect in your version: filter { s/a/b/ } @list shouldn't modify the original @list.
Let me go dig up my version...
Update: Make that two features. (: I also think that 'filter' in a scalar context should return the concatenated values (a count is pretty useless):
package filter;
use strict;
require Exporter;
{ my $nowarn= *import }
*import= \&Exporter::import;
use vars qw( @EXPORT );
@EXPORT= qw( filter );
sub filter(&@) {
my( $code, @vals )= @_;
# local( $_ ); # Done by the loop.
for( @vals ) {
$code->();
}
wantarray ? @vals : join "", @vals;
}
1;
Though I've only tested this a little.
- tye (filtering shouldn't be straining) |