in reply to Appending strings

#!/usr/bin/perl # http://perlmonks.org/?node_id=1142266 use strict; use warnings; my $path = "XX.YY.ZZ"; my $s = "(ABC | (~dEf & hIJ)) & ~LMn"; print $s =~ s/(\w+)/$path.$1/gr, "\n";

Replies are listed 'Best First'.
Re^2: Appending strings
by doofus (Acolyte) on Sep 17, 2015 at 00:26 UTC
    I tried it and it says : syntax error at t line 80, near "s/(\w+)/$path.$1/gr" Execution of t aborted due to compilation errors.
        This is perl, v5.8.8 built for x86_64-linux-thread-multi
      #!/usr/bin/perl # http://perlmonks.org/?node_id=1142266 use strict; use warnings; my $path = "XX.YY.ZZ"; my $s = "(ABC | (~dEf & hIJ)) & ~LMn"; (my $answer = $s) =~ s/(\w+)/$path.$1/g; print "$answer\n";

      Tweaked for older perls.