in reply to Re: Using a variable as pattern in substitution
in thread Using a variable as pattern in substitution

Wouldn't it be easier or quicker to do something along the lines of:

@array2 = grep {$_ =~ s/\b$stopword\b//g } @array1;

or does grep compare favorably to a foreach as far as efficiency?

Some people fall from grace. I prefer a running start...

UPDATE:

After thinking on this a bit, I think this solution would work for the problem. Fellow monks, please point out my folly if I'm wrong with this.

#!/usr/bin/perl use strict; my @list = qw( red blue orange yellow black brown green ); print join( ' ', @list ); print "\n"; @list = grep { m/e/io } @list; print join( ' ', @list ); print "\n";

I realize my regex isn't what the original poster was trying to do, but the idea is the same I believe.

This is what I was trying to say in response earlier but I seem to have had a brain fart this morning.

Replies are listed 'Best First'.
Re (3): Using a variable as pattern in substitution
by VSarkiss (Monsignor) on Jun 05, 2002 at 18:30 UTC

    Wouldn't it be easier or quicker to ...
    Maybe or maybe not, but it would also not do what the original is asking for. This is looping over the input data, not over the patterns. It's also generating a second array instead of doing it in-place. Regardless of speed, that's guaranteed to need more memory.