Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: What is the meaning of this line in Perl on linux?

by eyepopslikeamosquito (Archbishop)
on Mar 29, 2022 at 02:50 UTC ( [id://11142475]=note: print w/replies, xml ) Need Help??


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

Modern Windows is fine with forward slashes

Not quite, as described in more detail at: Re^4: windows perl and paths

BTW, I'm surprised nobody suggested using the tr transliteration operator: $localdir =~ tr{/}{\\};

Replies are listed 'Best First'.
Re^4: What is the meaning of this line in Perl on linux?
by Marshall (Canon) on Mar 29, 2022 at 03:58 UTC
    Ok. Excellent point!

    You point out what was probably the cause of my vaguely remembered problem:
    "However, Windows commands typically use forward slash for command line argument options".
    If forward slash means "option" then the command will "barf" with a forward slashed file path because it thinks that part of the file path is an option! That explains my error case!

    I think we are in 100% agreement about file paths within Perl. Perl itself will always get forward slashed file names. Always use forward slash for file paths within Perl programs.

    There is an exception if you want to launch a Windows system command. That may barf due to conflicts between an option switch vs a file path.

    If you need to do a translation for that reason, I would put a comment in the code as to why the "/" is being translated to "\".
    I stand by my recommendation not to translate formats unless you need to.

    Your suggestion about tr is also to be commended. For a one 2 one translation, nothing beats tr for performance.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (11)
As of 2024-04-23 21:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found