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

There is changing the Two forward slashes to two backward slashes

$localdir =~ s/\\\///g;

The above line can i use for changing the backward slashes to forward slashes

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

    Hopefully this makes it clearer:

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

    But for regexes, I would recommend using what I suggested:

    $localdir =~ s{\\}{/}g;

    But as I said, using a module for this is even better:

    use warnings; use strict; use Path::Class qw/foreign_file foreign_dir/; my $file = foreign_file('Win32', "..\\Hello\\World.txt"); print $file->as_foreign('Unix'), "\n"; # prints "../Hello/World.txt"
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: What is the meaning of this line in Perl on linux?
by Corion (Patriarch) on Mar 28, 2022 at 08:29 UTC

    No. The above line is a syntax error and Perl tells you so.

    Maybe you want to learn about Perl quoting rules for strings? The backslash \ is special in Perl strings and is used to mark the next character as exempt from the quoting rules. See Quote-and-Quote-like-Operators, especially the section about Escape Sequences. There it explains why you need to write \\ when you want to match a single \ in a regular expression.

      No. The above line is a syntax error and Perl tells you so.

      At first glance I thought so too, but it's actually not - it's just s{\\\/}{}g. LTS strikes again :-)

      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.

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