Searching \ for '%Perl Programmers? Filter a list?%' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/devprogs.htm?key=programmer
Search entire site for: 'Perl Programmers? Filter a list?'.

_Sub string match.
PICList Thread
'[OT]: Perl Programmers? Filter a list?'
2001\04\26@200023 by jamesnewton

picon face
I'm again pounding my head against PERL. "Me and Perl, see? We don't see eye
to eye, see? I see in C, see? Or in ASM or ASP, see?" <GRIN>

This time its for a client... and time is "of the essence"

How does one efficiently filter unwanted elements out of an array? I mean
list?

In VBScript (ASP pages) it is

join(filter(array("1ws","2ws","3server","4ws"),"server",False),", ")

which will return "1ws, 2ws, 4ws"

Do I really have to do something like:

foreach $element (@in) {
if (!($element =~ m/4/i)) {@out = {@out,$element};}
}

Oh God! That can't be right. If anything, this probably shows how much I
don't understand Perl. <GRIN>

HELLLLLLLLLP!

---
James Newton (PICList Admin #3)
spam_OUTjamesnewtonTakeThisOuTspampiclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2001\04\26@204453 by jamesnewton

face picon face
Oh, I just figured out that push has nothing to do with stacks...
...unless you think of every array as a stack. Perl is just weird to me...

foreach $element (@in) {
if (!($element =~ m/4/i)) {push @out,$element;}
}

getting better...

---
James Newton (PICList Admin #3)
jamesnewtonspamKILLspampiclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

{Original Message removed}

2001\04\26@210405 by jamesnewton

face picon face
Is it

foreach (@in) {push(@out) unless /.*server$/}

?

Is there no way to do this without two arrays? lists? whatever?

---
James Newton (PICList Admin #3)
.....jamesnewtonKILLspamspam.....piclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

{Original Message removed}

2001\04\27@003904 by klpauba

picon face
You heard the perl motto, haven't you -- "there's more than one way to
do it" (or some such).

Here's what I often use:

@in = ('one', 'two_server', 'three');

@out = grep($_ !~ /server$/, @in);

print join(',', @out) . "\n";


Basically, the 'grep' command takes each element of the second argument
(@in) and assigns it to $_ and then evaluates the first argument (any
perl expression) and assembles a list of the elements when the
expression evaluates to true.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\04\27@060655 by Peter L. Peres

picon face
There is more than one way to do it in Perl [tm]. Which one is more
efficient depends on many things. You can set up a test bench and run each
implementation on it and measure time or something else if you really want
to know. The VB version uses at least an array of pointers of thes size of
the input array but it does not tell you about it.

Peter

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...