in reply to Re: Storing Regular Expressions as Strings in Array??
in thread Storing Regular Expressions as Strings in Array??

I had to make the following change to the above snippet to be able to make it work as intended... i.e. the $string ends up as "bar zaz".

my @subs; push @subs,sub{local $_=shift; s/foo/bar/g; $_}; push @subs,sub{local $_=shift; s/baz/zaz/g; $_}; my $string="foo baz"; $string = $_->($string) foreach @subs; # *** CHANGED *** # print $string;

Thanks for the code though, it was very helpful

Replies are listed 'Best First'.
Re: Code Correction
by demerphq (Chancellor) on May 03, 2002 at 08:26 UTC
    Doh.

    Of course. The way I did it would work only if the subs were written as

    sub{$_[0]=~s/foo/bar/g; $_[0]}
    Sorry about the confusion...

    Glad it helped out though. :-)

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.