Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

File Paths of Shared Packages

by mikasue (Friar)
on Oct 14, 2011 at 16:00 UTC ( #931546=perlquestion: print w/ replies, xml ) Need Help??
mikasue has asked for the wisdom of the Perl Monks concerning the following question:

Good morning! I have a question about filenames and paths in Perl. I use the the FindBin command to find my current working directory but I need to go one level up out of my current directory. Is there a command that will allow me to do that and then set the lib "." to that level so that I can share a .pm file that's in that directory?

Example
/foo/poo/current/
when I use FindBin i get /foo/poo/current/
but the file I want to use is in /foo/poo

Thanks!
MikaSue

Comment on File Paths of Shared Packages
Re: File Paths of Shared Packages
by AnomalousMonk (Monsignor) on Oct 14, 2011 at 16:23 UTC

    The synopsis of FindBin seems to give an example of what I understand you want to do.

    c:\@Work\Perl\junque>perl -wMstrict -le "use FindBin; use lib qq{$FindBin::Bin/../monks}; ;; print qq{$FindBin::Bin}; printf qq{'$_' } for @INC; " c:/@Work/Perl/junque 'c:/@Work/Perl/junque/../monks' 'C:/strawberry/5.12/perl/site/lib' 'C +:/strawberry/5.12/perl/vendor/lib' 'C:/strawberry/5.12/perl/lib' '.'

    Update:

    I use the the FindBin command to find my current working directory ...

    Note that the current working directory and the directory in which the script resides (returned by FindBin) may only be the same by chance. For the reliable current working directory, use something like Cwd.

Re: File Paths of Shared Packages
by Eliya (Vicar) on Oct 14, 2011 at 16:40 UTC
    but I need to go one level up

    ".." goes one level up, so if $FindBin::Bin is "/foo/poo/current", the path "$FindBin::Bin/.." is interpreted by the OS as "/foo/poo".  So:

    use FindBin; use lib "$FindBin::Bin/..";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://931546]
Approved by Eliya
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2014-07-22 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (127 votes), past polls