Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Compatibility on Win32 and UNIX

by perlisfun (Sexton)
on May 10, 2002 at 15:48 UTC ( #165674=perlquestion: print w/replies, xml ) Need Help??

perlisfun has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Is there any way to write perl script to run on Win32 and UNIX both without worrying path format '/path/thisway' on UNIX and '\path\thisway' on Win32 Thanks,

Replies are listed 'Best First'.
Re: Compatibility on Win32 and UNIX
by rinceWind (Monsignor) on May 10, 2002 at 15:59 UTC
    Check out modules File::Spec in the core distribution. These cope with many more file path syntaxes than Unix and Win32. For example: VMS

    If you want your code to be truly portable (which is a good aim), you should be using modules such as File::Spec to handle the fine details of paths.

    One thing to be careful of though is case sensitivity. Unix is case sensitive, whereas Win32 only pretends to be.

Re: Compatibility on Win32 and UNIX
by atopolc (Pilgrim) on May 10, 2002 at 16:04 UTC
    You could check the  $^O variable and switch the path format depending on the result.

    $^O eq "hpux" ? $path='/path/thisway':$path='\path\thisway';

      Don't do it. It is ugly. Just use File::Spec. Let perl hackers who maintain this module worry which slash to use on which platform.
      use File::Spec; $path = File::Spec->catfile('path', 'thisway');

      Ilya Martynov (

        Thanks and appreciations go to all of you. Have a good weekend.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://165674]
Approved by rinceWind
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2022-01-17 06:35 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (51 votes). Check out past polls.