in reply to Re^3: What is the meaning of this line in Perl on linux?
in thread What is the meaning of this line in Perl on linux?

I want to change the two backward slashes to two forward Slashes. For that anyone can provide the syntax for changing the two backward slashes to two forward Slashes.

  • Comment on Re^4: What is the meaning of this line in Perl on linux?

Replies are listed 'Best First'.
Re^5: What is the meaning of this line in Perl on linux?
by Corion (Patriarch) on Mar 28, 2022 at 08:33 UTC

    Yes. The line you posted in your first post actually works for that. We told you so. Where is your question?

      In my post that is for changing the forward slash to backward slash. Now i am asking fo changing the backward slash to forward slash.

        Then you need to swap the part that is searched with the part that is replaced.

        Currently, as haukex already explained, you have:

        # delimiters # | | | # v v v $localdir =~ s/\//\\/g; # ^^ ^^ # | | # search part replacement

        So, if you swap search part and replacement, you get:

        # delimiters # | | | # v v v $localdir =~ s/\\/\//g; # ^^ ^^ # | | # search part replacement

        The above gets much clearer if you use another delimiter instead of s///g, for example, s{}{}g. Then your original line is

        # delimiters # | || | # v vv v $localdir =~ s{/}{\\}g; # ^ ^^ # | | # search part replacement

        With the swap of search part and replacement part, that becomes:

        <c> # delimiters # | || | # v vv v $localdir =~ s{\\}{/}g; # ^^ ^ # | | # search part replacement