in reply to Re: sorting an array with an array
in thread sorting an array with an array

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)

Replies are listed 'Best First'.
Re: sorting an array with an array
by Abigail-II (Bishop) on Oct 01, 2002 at 16:54 UTC
    sub filter (&@) {map {local $_ = $_; $_ [0] -> (); $_} @_ [1 .. $# +_]}

    Abigail