Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

how to add script directory to @INC

by bdimych (Monk)
on Jan 11, 2009 at 17:59 UTC ( #735537=perlquestion: print w/replies, xml ) Need Help??

bdimych has asked for the wisdom of the Perl Monks concerning the following question:

is there something shorter than
BEGIN {unshift @INC, $1 if $0 =~ m|(.*)/|}

thanks

Replies are listed 'Best First'.
Re: how to add script directory to @INC
by ikegami (Patriarch) on Jan 11, 2009 at 18:02 UTC

    Shorter:

    use lib $0 =~ m|(.*)/|;

    But how about something that actually works instead. What you have there doesn't handle symlinks or non-unix systems.

    use Cwd qw( realpath ); use File::Basename qw( dirname ); use lib dirname(realpath($0));
Re: how to add script directory to @INC
by ysth (Canon) on Jan 11, 2009 at 22:49 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2023-09-23 17:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?