NT Perl 5 and slash vs. backslash 
Author Message
 NT Perl 5 and slash vs. backslash

NT Perl from hip.com seems to accomodate the NT filesystem's
ideosynchrasy of using the backslash to delimit directories, at least
when it can. For instance, when you try to open() a file or rmdir() a
directory, paths can be delimited by the slash.
        Nowhere can I find this documented, though.
        When a command is going to be invoked by the system, though (e.g. via
system() or a backtick-delimited literal), the path must be delimited by
backslashes. Since the backslash is the escape metacharacter, these must
be doubled-up to have the intended meaning. (e.g.
system("\\bin\\myexe.exe"))
        Is there a discussion on this topic to which I can turn for further
information.

--dwb--

--
----------------------------------------------------------------
David W. Baker                       Associate Systems Developer



Mon, 13 Jul 1998 03:00:00 GMT  
 NT Perl 5 and slash vs. backslash


Quote:
> NT Perl from hip.com seems to accomodate the NT filesystem's
> ideosynchrasy of using the backslash to delimit directories, at least
> when it can. For instance, when you try to open() a file or rmdir() a
> directory, paths can be delimited by the slash.
>       Nowhere can I find this documented, though.
>       When a command is going to be invoked by the system, though (e.g. via
> system() or a backtick-delimited literal), the path must be delimited by
> backslashes. Since the backslash is the escape metacharacter, these must
> be doubled-up to have the intended meaning. (e.g.
> system("\\bin\\myexe.exe"))
>       Is there a discussion on this topic to which I can turn for further
> information.

I think you've said all there is to say on the topic!

I deal with the same problem under OS/2. Perhaps LONG LONG AGO
when someone was selling MSDOS (or perhaps CP/M) they decided to
DIFFERENTIATE their product from Unix by using backslashes instead
of slashes. We have them to thank!

Anyway, I think of the issue this way: the Perl language uses a slash
as delimiter path regardless of what the shell uses.

Commands like system or exec or `shell_command` just pass strings
to the shell, and so must give the shell what it wants.

I solve the problem by using slashes in all paths, and then when I
want to pass a string to the OS, I just use a subroutine to substitute
backslashes for slashes. One needs to indicate DOS'ish switches by '#'
(or somesuch) instead of '/' to avoid destroying them by accident.

   $foopath = '/perl5/lib';
   $command = &dos_path ("dir $foopath #p");
   print $command . "\n"; # always check'em
   $result_code = system ($command) / 256;

   sub dos_path {

      $path =~ s,/,\\,g;
      $path =~ s,#,/,g;
      $path;
   }

--
Joel Roth



Fri, 17 Jul 1998 03:00:00 GMT  
 NT Perl 5 and slash vs. backslash

Quote:

>I deal with the same problem under OS/2. Perhaps LONG LONG AGO
>when someone was selling MSDOS (or perhaps CP/M) they decided to
>DIFFERENTIATE their product from Unix by using backslashes instead
>of slashes. We have them to thank!

    Actually it's because MSDOS was made to look like CP/M which in turn
    had copied its command-line conventions from DEC's TOPS10, an operating
    system used on PDP10s (an almost mainframe).  The syntax  for program
    options was to use the / character to introduce what were  called
    program switches.

        > FOO/OP1/OP2  PARAM1  PARAM2/OP4  ...

    In this example, options OP1 and OP2 modify the overall operation of
    program FOO, and the OP4 option applies to the second parameter only.
    This is basically the syntax that is used today in VMS, which of course
    is a descendant of TOPS10.

    In any case, when subdirectories were later added to MSDOS, they
    needed a syntax for directory paths.  They could have continued copying
    DEC's syntax

                d:[dir.dir.dir]file.ext

    but at the time Unix was an up and coming operating system so they
    decided to copy that instead.  However, in order to maintain backward
    compatibility with those original DOS programs that accepted options,
    Microsoft picked backslashes instead.  Ironically given the primitive
    nature of most programs I saw on DOS in the pre-subdirectory days (only
    version 1?), *damn* *few* programs even knew what an option was.  So
    even in the not so long run, it was a real-bad-choice(tm).

    I bet that was much more than you wanted to know on the subject. ;^)

                                                Later....BC


##    ###   ##    ## | Bill Costa                                          |
##    ####  ##    ## | Computing & Information Srvs                        |
##    ## ## ######## | Kingsbury Hall               PHONE: +1-603-862-3056 |
##    ##  ####    ## | University of New Hampshire    FAX: +1-603-862-4778 |
##    ##   ###    ## | Durham, NH  03824-3591  USA                         |
 #######    ##    ## +----------------[ No good deed goes un-punished. ]---+



Sat, 18 Jul 1998 03:00:00 GMT  
 NT Perl 5 and slash vs. backslash

Quote:

>I deal with the same problem under OS/2. Perhaps LONG LONG AGO
>when someone was selling MSDOS (or perhaps CP/M) they decided to
>DIFFERENTIATE their product from Unix by using backslashes instead
>of slashes. We have them to thank!

It happened a bit differently - but no less stupidly.

CP/M didn't even *have* the concept of subdirectories.  
Each drive had only one directory.  No problemo since the
floppy drives on the CP/M systems weren't very big anyway.
The '/' character was used to denote switches on the command
line, which UNIX of course does with the '-' char.  The /switch
syntax was a legacy of early Digital Equipment Corp. OS's like
RSX-11, RSTS, and RT-11.  CP/M copied many ideas from RT-11
and scaled them down for 8Kb 8080 systems.

When the first PC was prototyping, MS bought the rights to
a CP/M clone for the 8088 CPU, called it PC-DOS, and licensed
it to IBM.  One oft forgotten fact about PC-DOS version 1.0 is
that, just like the CP/M it was modelled on, it had a flat
filesystem (no subdirectories).  DOS V2 was the first to have
that.  So there was no conflict in using '/' as a switch
char in V1.  Then when they added hierarchical dirs to DOS,
they used '\' to separate dirs, in a misguided effort to
avoid breaking applications written for V1 DOS.  Rrrrrr.
We've had to live with that stupid decision ever since,
even down through OS/2 and other bend-over-backward-for-DOS
OS's.

ObPerl:  sorry, no perl content here whatsoever.

((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((

'77 KZ650 "Kawaski"    DoD #1146
"The ultimate result of shielding men from the results of their own folly
 is to fill the world with fools" -- Herbert Spencer
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))



Sun, 19 Jul 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Slash vs backslash in nt vs 95?

2. problem with slash and backslash : strange behaviour with different PC

3. Filename seperators - slash or backslash!

4. Substituting backslash for 2 forward slashes

5. back vs. forward slash

6. Changing back slashes to forward slashes

7. Use of Backslash in PERL on NT

8. Perl on NT vs Perl on Win98

9. NT Perl vs UNIX Perl

10. NT Perl vs. Win95 Perl

11. Q: Perl for Unix Vs. Perl for NT

12. Perl for NT vs. Perl for Unix

 

 
Powered by phpBB® Forum Software