Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: windows perl and paths

by ww (Archbishop)
on Nov 19, 2016 at 19:03 UTC ( [id://1176167]=note: print w/replies, xml ) Need Help??


in reply to Re^2: windows perl and paths
in thread windows perl and paths

Could it be the nature of the test?

Running your code seems to me to show that -- as asserted with respect to the use of forward slashes in windows -- M$ sees the two as equivalent (or "equal?") while perl does not. *1

*1UPDATE! Sloppy language on my part. Insert "paths" before the closing double-hyphen. See, especially, eyepopslikeamosquito's at this node.

Formatting in the code, the end block, etc. solely to make my reading of it easier.

#!/usr/bin/perl -w use strict; #1176161 my $x = qq{Z:\/Partners\/Wilsons\/2push_test}; my $y = 'Z:\Partners\Wilsons\2push_test'; print qq{'$x' '$y'}; print "\n\t"; END { print "Not equivalent! \n" unless $x eq $y; } END { # multiple end blocks are executed in rev +erse order if ($!) { print "Error is $!, \n"; } else { print "No (perl) error found.\n\t Done with the second END bl +ock\n\n"; } } exit();
and output, as expected:
C:\Users\wheelerw>D:\_Perl_\PMonks\1176161.pl 'Z:/Partners/Wilsons/2push_test' 'Z:\Partners\Wilson No (perl) error found. Done with the second END block Not equivalent!

Replies are listed 'Best First'.
Re^4: windows perl and paths
by AnomalousMonk (Archbishop) on Nov 19, 2016 at 19:59 UTC

    I expressed myself rather poorly.

    What I meant to convey was my lack of understanding of the assertion in the OP of a need to escape forward slashes in the example code given in the OP, and my understanding, shared alike by all who replied in this thread, that Perl was quite happy with forward slashes in strings, paths, etc., regardless of OS, and equally happy with backslashes (if you can figure out the proper way to get them into a string) in paths under Windows.

    Rather vapidly, I went off on the tangent of wittering on about the differences between the strings that Athanasius gave as examples, ignoring, if only for the moment, their equivalence as paths. Oh, well...


    Give a man a fish:  <%-{-{-{-<

      Hello AnomalousMonk,

      Of course, you’re right, I meant to say that the strings "Z:\\Partners\\Wilsons\\2push_test" and 'Z:\Partners\Wilsons\2push_test' are equivalent.

      But yes, under Windows, back slashes and forward slashes are interchangeable as path separators.

      Good catch!

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re^4: windows perl and paths
by eyepopslikeamosquito (Archbishop) on Nov 20, 2016 at 05:37 UTC

    ...with respect to the use of forward slashes in windows -- M$ sees the two as equivalent...
    To be more precise, the Windows API treats forward slashes and back slashes equivalently in file path arguments to all Windows API functions. However, Windows commands typically use forward slash for command line argument options.

    So, while using forward slashes in file paths is fine when calling Win32 API functions (as the perl C sources do when built for Windows), using them in command line arguments when running Windows commands can be problematic.

    In my Perl programs on Windows, I use forward slashes in all file paths, which works fine when calling all Perl internal functions. In the rare cases where I need to pass a file path to an external Windows command, I translate it like so: $filepath =~ tr{/}{\\};

    See also: forward vs back slash python question.

    Update: Note that all Win32 API functions have always treated forward slashes and back slashes equivalently in file path arguments. See also Re^2: What is the meaning of this line in Perl on linux? and Re^4: Changing filename extensions.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1176167]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-26 05:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found