in reply to replace / with \ using regular expressions?

$command =~ s!/!\\!g;    # Swap '/' for '\'

Replies are listed 'Best First'.
Re^2: replace / with \ using regular expressions?
by afoken (Chancellor) on Jun 20, 2009 at 08:03 UTC

    tr|/|\\| should be more efficient.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      thanks Alex.
Re^2: replace / with \ using regular expressions?
by Anonymous Monk on Jun 20, 2009 at 07:46 UTC
    I have string say C:/this/is/atest/ i need to replace this with C:\this\is\atest\?
      What the problem is?
      $command = 'C:/this/is/atest/'; $command =~ s!/!\\!g; # Swap '/' for '\' die $command; __END__ C:\this\is\atest\ at - line 3.
        thanks i got it.