Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: standard library to return system paths

by Corion (Patriarch)
on Jun 07, 2016 at 06:50 UTC ( [id://1165034]=note: print w/replies, xml ) Need Help??


in reply to Re^2: standard library to return system paths
in thread standard library to return system paths

Maybe see File::HomeDir.

Note that on Windows, C:\Program Files is not universal - it might localized to the language that Windows was installed to.

There is no universal idea of where libraries get installed to, even on Linuxish OSes, you might have /lib, /usr/lib and /lib64.

Maybe you will get better answers if you can tell us what exact problem you are trying to solve.

Replies are listed 'Best First'.
Re^4: standard library to return system paths
by igoryonya (Pilgrim) on Jun 07, 2016 at 07:16 UTC
    > "Note that on Windows, C:\Program Files is not universal - it might localized to the language that Windows was installed to."

    Yes, that's why I was looking for a lib, that find such dirs, depending, on what OS, the perl program is launched.

    Unfortunately, File::HomeDir is not a standard module. It's not helping.
    It's like a catch 22, I order to run a program with libraries, I need to be able to tell my program to tell, where those libraries are. In order to tell, where the libraries are, I have to tell load a library, that can tell it. That's why I need a module, or a variable, that's is standard on perl distros.

      You can usually assume that your libraries are in some fixed place relative to the script path which you can find as $0.

      Example:

      # untested! use File::Spec; BEGIN { my $script = File::Spec->rel2abs($0); my ($drive, $dir) = File::Spec->splitpath($script); my $base = File::Spec->catpath($drive, $dir); if ($^O eq 'MSWin32') { push @INC, "$base\\lib"; } else { push @INC, "$base/../lib"; } }
      You just have to ensure that your Perl applications are installed using the fixed directory structure matching your code expectations.

      Update: Also, on Windows you may like to store the path to your application on the registry when it is installed.

        Yes, you are correct, but... this type of thing I wanted to get away from, because it's a pain to add the same code to every program, that you do, so, exactly, I've put code similar to that in a library, that was placed to /etc/ folder and started just calling: require /etc/somelib.pl, like that.

        This approach has several problems:
        1) it wouldn't work on most public webservers, because, I don't have a writeable access to /etc folder on a shared computer.
        2) Windows has a different path for such folder, i.e.: c:\users\appdata\, or c:\program files\all users\application data, or it could even be on a different drive.

        So, I am facing not only a crossplatformness problem, but even on the same OS family, it could be located in different place, depending on the computer.

        After some further thought, that none of the answers gave me a desirable solution, I've came up with a solution, listed in my message update, that I find reasonable for the task: creating a crossplatform installer for sort of script 'boot loader' library.
        A simple library, that will be installed to a standard perl path, that will determine everything else in the currently running system.

        Later, I will fix it to detect the path, that the installer can write to, so the installer doesn't have to have super user privileges, I hope.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1165034]
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: (3)
As of 2024-04-19 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found