Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Filename Surrounded by Quotes in a Scalar Variable Causes Open to Fail

by pryrt (Abbot)
on Sep 03, 2020 at 21:29 UTC ( [id://11121336]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Filename Surrounded by Quotes in a Scalar Variable Causes Open to Fail
in thread Filename Surrounded by Quotes in a Scalar Variable Causes Open to Fail

it just seems odd that Perl's open doesn't just ignore the surrounding quotes

It would seem odd (and a bug) to me if Perl's open did just ignore the quote characters in the string I pass as the filename. If I send a string to that third argument of open, that is the exact text I want as the filename. If Perl started ignoring my characters without my permission, I'd get annoyed.

And in Linux environments, quotes are perfectly valid characters inside filenames, so if I wanted my file named `"QuotedFilename"` in Linux, and Perl silently stripped those characters for me, I'd really be annoyed.

I use the quoted filename in the scalar variable other places for other things

In that case, I would store the filename variable as the actual name of the file, and then properly quote it for whatever environment you're sending that filename to. The quoting is part of the environment's requirement, not part of the filename. (By "environment", I don't mean %ENV; I mean it in the sense of "All the elements that affect a system or its inputs and outputs." -- wiktionary:environment)

  • Comment on Re^3: Filename Surrounded by Quotes in a Scalar Variable Causes Open to Fail
  • Download Code

Replies are listed 'Best First'.
Re^4: Filename Surrounded by Quotes in a Scalar Variable Causes Open to Fail
by roho (Bishop) on Sep 03, 2020 at 21:39 UTC
    Understood. You're right. If Perl started removing quote characters without permission that would open the door to all sorts of unintended consequences.

    I'm focused on developing on Windows at the moment, and I forgot about the other environments (*nix, etc.) that have different rules and allow different characters in filenames.

    Thanks again for your input and clarification.

    "It's not how hard you work, it's how much you get done."

      I currently develop Perl code exclusively on Windows. However, some of my clients run my code on Unix and it almost always works even though I don't test it. My code does not create any filename that would not be a proper Perl variable name. That is more restrictive than it needs to be. However, if I create file "abc_123" (no spaces in the file name) from "abc 123" that does not seem to cause any significant issues for Windows users - they get it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-24 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found