in reply to Replace strings with "("

See perldoc perlre :)
my $string = 'test("test ... bla bla bla")'; $string =~ s/test\("test/test\("GC_test/;

Replies are listed 'Best First'.
Re^2: Replace strings with "("
by chintak86 (Initiate) on Jan 30, 2005 at 00:07 UTC
    That was the first thing I tried. The problem with that was, the strings weren't modified. It remained test("test.
    I don't know if this info is relevant, but I will share with you if it helps. I am using active perl on windows 2000.
    The regex I tried to use came from another site on active perl. I can't remember which site it was from though. There it was mentioned to put the paren inside a open and close paren and quote the paren in the string. i.e. (\()
    By the way I did try your solution just in case. But I still have my initial result. Any help would be appreciated. Thanks
      Are you reading these in from a file and seeing that their not changed in the file ?

      If so, try this recipe for in-place editing

      prompt> perl -i -pe 's/"t/"GC_t/' file_to_be_changed.txt

      The -i flag tells perl to make changes (like regex substitutions) in the original file, dont make a backup

      The -pe is two options joined together - -p is print every line in the supplied file back out to itself (thats what -i and -p together do - print every line back to the same file)

      The -e tells perl to apply the regex to every line in the file - and hence the "t lines become "GC_t before being printed back out.

      You can find more options like these in "perldoc perlrun", or Perl Command-Line Options.

      Cheers

      ...it is better to be approximately right than precisely wrong. - Warren Buffet

      with perl 5.8.4 on linux(debian unstable), the following code
      1 #!/usr/bin/perl 2 3 use strict; 4 5 my $string = 'test("test ... bla bla bla")'; 6 $string =~ s/test\("test/test\("GC_test/; 7 8 print $string."\n";
      return test("GC_test ... bla bla bla")

      perhaps the probleme is your verion of perl