In my current incarnation as "pocket protector man," we work on both UNIX and WIN32 machines. Sometimes it's handy to be able to convert all the backslashes to forward slashes, and reverse. The first regex does the former, the second the latter.
I know how to change the delimiter, I just like the way it looks the way it is, sortof minimalistic. Of course this has probably been posted here before, but since I'm new to Perl (reletively speaking) I think it's pretty cool.
s/\//\\/g s/\\/\//g
</CODE>

Replies are listed 'Best First'.
RE: slash converter
by turnstep (Parson) on May 01, 2000 at 18:15 UTC
    A fine example of LTS! :)
      what is a 'LTS' please? sc
        LTS = "leaning toothpick syndrome". Look at an escaped forward slash: "\/". Do a bunch of escaping like this and it all starts to look like leaning toothpicks.
RE: slash converter
by KM (Priest) on May 20, 2000 at 02:53 UTC
    You do know that Win32 systems can use forward slashes, right? c:/windows/temp is valid.
      <quote>"You do know that Win32 systems can use forward slashes, right? c:/windows/temp is valid."</quote>
      This is no longer true. Win2K does not support the forward slash anymore. It assumes that you are refering to a flag of somekind and bombs out with an error.

      UPDATE: Since KM does not believe me that Win2K will bomb I went back to my W2K box and ran a simple test. I opened a command prompt at the C:\ level and called
      dir c:\perl5
          and
      dir c:/perl5
      and what-do-you-know! The first method (backslash) returned the contents of the perl5 directory and the second method (forward-slash) generated the error:

      Parameter format not correct - "perl5".

      I hope this is sufficient information for you KM.

        Because I work in Perl exclusively on a win2k box, run scripts from that box daily that use the forward slash, and only use the forward slash b/c I hate writing \\\\ before a server, you can mark me a dissenter.

        The forward slash absolutely works with an install of ActiveState 6.15 on a win2k box

        Update:I did something like the original post in this thread here

        -OzzyOsbourne

        FWIW, dir "C:/TEMP" does work.

        Cheers,
        Shendal
        Does this apply to both Perl functions and command-line arguments, or just the CLI? "Switches" in filenames is particularly useless, so I wonder if an open(F, "/somedir/filename.txt") would work identically on Unix and Win2k?
        I feel lucky that I wouldn't know that Win2K no longer supports this. However, I would need to see it to believe it. I do know that 98/NT does support this.

        Cheers,
        KM