Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

File Paths of Shared Packages

by mikasue (Friar)
on Oct 14, 2011 at 16:00 UTC ( [id://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

Replies are listed 'Best First'.
Re: File Paths of Shared Packages
by AnomalousMonk (Archbishop) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-29 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found