Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: @INC from $0

by BrowserUk (Patriarch)
on Jul 24, 2015 at 01:51 UTC ( [id://1136104]=note: print w/replies, xml ) Need Help??


in reply to Re^2: @INC from $0
in thread @INC from $0

Then wrap it in a BEGIN block.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Replies are listed 'Best First'.
Re^4: @INC from $0
by Anonymous Monk on Jul 24, 2015 at 01:54 UTC

    Then wrap it in a BEGIN block.

    Same issue  BEGIN{($_ = $0) =~ s[[\\/][^\\/]+$][]; use lib $_;}

      Is matter of order?..(UPDATE: evidently not seen the anonym's answer above..)
      BEGIN{($path = $0) =~ s[[\\/][^\\/]+$][];} BEGIN{ use lib $path;}

      gives no error.

      L*
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
        BEGIN{($path = $0) =~ s[[\\/][^\\/]+$][];} BEGIN{ use lib $path;}

        use implies BEGIN, so that BEGIN should not be needed.

        There is a simpler way: use lib do { ... }, shown in Re^2: Calculations before using lib;. Combined with the s///r syntax from newer perls, this can be collapsed to use lib do { $0=~s[[\\/][^\\/]+$][]r };.

        Also note that $0 may not always contain an absolute path:

        >cat tmp.pl #!/usr/bin/perl use strict; use warnings; print "$0\n"; >chmod +x tmp.pl >perl tmp.pl tmp.pl >perl ./tmp.pl ./tmp.pl >perl /tmp/tmp.pl /tmp/tmp.pl >./tmp.pl ./tmp.pl >tmp.pl ./tmp.pl >

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      BEGIN{ ($_ = $0) =~ s[[\\/][^\\/]+$][]; } use lib $_;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2024-03-28 10:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found