Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: open file error

by jellisii2 (Hermit)
on Jul 19, 2016 at 16:57 UTC ( [id://1168064]=note: print w/replies, xml ) Need Help??


in reply to open file error

I would also suggest use of File::Spec for building out path names. I don't know that it would have cleaned up your variable or not, but its a good habit to use it when assembling paths.

That said, I may be one of those weirdos that has had to write code that works on multiple platforms and been bitten by this. :)

Replies are listed 'Best First'.
Re^2: open file error
by afoken (Chancellor) on Jul 20, 2016 at 05:10 UTC

    File::Spec makes two assumptions:

    1. File system rules depend only on the operating system
    2. A set of file system rules choosen for an operating system is valid for all mounted file systems.

    Both assumptions are wrong at least for Linux (see "Filesystem Specific Mount Options" in mount(8)), probably all modern Unix derivates, and so File::Spec can return wrong results.

    See also Re^5: Unify windows filenames.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^2: open file error
by RonW (Parson) on Jul 19, 2016 at 22:14 UTC

    It has been a long time since I've had to write a Perl program that had to support an OS other than Linux/Unix/POSIX, MS Windows and Mac OSX.

    Internally, MS Windows accepts / as a path separater. It is cmd.exe that has a problem because it treats / as the option introducer. So, c:/path/to/file or even c:\path\to/file are valid.

    Of course, Linux/etc and Mac OSX don't use volume designaters ("drive letters"), so would try to treat "c:" as a directory in the current directory, but, so far, in the Perl programs I've written, the only source of volume designaters is from user input (either directly or through a file dialog box).

    In the rare case I have to start cmd.exe from Perl, I have used File::Spec::canonpath to insure the file path is acceptable.

    Otherwise, I usually treat file paths as POSIX style and have no problems.

    For example, to split a path, I just use

    @dirs = split qr{[\\/]}, $path; $file = pop @dirs unless -d $path;

    And to assemble a path

    $path = '/' . join '/', @dirs, ($file // '');

    Mostly, I don't care about the volume. If I need it, it's in $dirs[0].

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-19 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found