in reply to Replacing multiple matches

my @matches = $loop_line =~/\[(.*?)\]/; # Build a list of matches for ( @matches ) { $loop_line =~ s/\Q$_\E/$replace{$_}/; # \Q makes sure no strange t +hings happen }

Hope this helps.
There must be a faster way, but I can't think of one now.

Update: Added ?, as our dear Abigail supposed.

---
Berik

Replies are listed 'Best First'.
Re: Replacing multiple matches
by Abigail-II (Bishop) on Feb 16, 2004 at 12:08 UTC
    Rubbish.
    #!/usr/bin/perl use strict; use warnings; my $loop_line = "static replace [something] and [another] thing"; my @matches = $loop_line =~/\[(.*)\]/; # Build a list of matches for ( @matches ) { $loop_line =~ s/\Q$_\E/PING/; } print $loop_line, "\n"; __END__ static replace [PING] thing
    The problem with the given code is the use of .*, which your solution doesn't solve at all. In fact, your solution doesn't address any problem. It's just adding slowness. It's worse than not giving an answer.

    Abigail

      /Off Topic/
      I don't see how this reply must have helped alongwor with his problem. Mine at least pointed him somewhat in the right direction. We all make errors, I even dare to say you make them too. But I thought that this website is all about learning, so you should make errors.

      Thanx.
      Update: I'm sorry for misreading, and thereby not suppling the answere. But I still do not agree with Abigail's reply.

      Hmm, I guess my post was rubbish after all, forget what I have posted here.
      Will do better next time.
      ---
      Berik
        I don't get it. Are you trying to say it's in every ones best interest to give wrong answers, and not have those answers be pointed out as being wrong?

        If not, then what are you trying to say?

        Abigail