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):
Though I've only tested this a little. - tye (filtering shouldn't be straining)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;
In reply to (tye)Re3: sorting an array with an array
by tye
in thread sorting an array with an array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |