Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Array sifting, maintaining order

by japhy (Canon)
on Dec 10, 2001 at 20:26 UTC ( [id://130691]=CUFP: print w/replies, xml ) Need Help??

Like Array sifting, but the order is kept intact.
sub sift (\@@) { my $in = shift; my ($i,$j) = (0,0); my @s; @_ = map ref($_) ? $_ : qr/$_/, @_; push @s, map { my $ok = 0; my $e = $_; for my $r (@_) { splice(@$in, $i-$j++, $ok = 1), last if /$r/; } $i++; $ok ? $e : () } @$in; return @s; } @orig = qw( where are going to you ); @sifted = sift @orig, qr/^[aeiouy]/, qr/ng$/; print "@sifted;@orig\n"; # are going you;where to

Replies are listed 'Best First'.
Re: Array sifting, maintaining order
by zentara (Archbishop) on Dec 17, 2001 at 03:34 UTC
    I'm just a novice, so I can't really find the error, but when I run this code I get are going you;to you not are going you;where to
      Thank you for pointing that out. I have corrected the code.

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://130691]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found