in reply to Re: Replacing multiple matches
in thread Replacing multiple matches

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

Replies are listed 'Best First'.
Re: Re: Replacing multiple matches
by Berik (Sexton) on Feb 17, 2004 at 00:05 UTC
    /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