Hi Irfan Sayed,

 Please check my comments below.

On 8/18/12, Irfan Sayed <[email protected]> wrote:
> hi,
>
> i have string like this :
> $a = '$(workspace)\convergence\trunk';
>
> i need to replace $(workspace) with 'c:\p4\abc'
> i wrote regex like this :
>
> $a =~ s/$\(workspace)/c:\\p4\\abc/;
> however, the string which i am getting is :

  Please, try not to use variable $a and $b, those are default to sort
function in Perl.

> $(c:\p4\abc)\convergence\trunk
>
> i need output like this : c:\p4\abc\convergence\trunk
> somehow, i am not getting, how to escape, $ and braces

  You can do that like so:

use warnings;
use strict;

my $str     = '$(workspace)\convergence\trunk';
my $replace_str = qr{\Q$(workspace)};

$str =~ s{
        $replace_str                    ## replacement string
        (?<name>\\.+?)$              ## part of the original string named
       }
       {
        print "c:\\p4\\abc",$+{name} ## print new string
       }xe;

__END__

OUTPUT:
c:\p4\abc\convergence\trunk

Please check "perldoc perlretut" for more detailed infomation.

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to