Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: use lib statement with path variable

by Eily (Parson)
on Dec 04, 2013 at 19:55 UTC ( #1065644=note: print w/replies, xml ) Need Help??


in reply to Re^2: use lib statement with path variable
in thread use lib statement with path variable

There are two problems there. qw takes each blank characters separated elements in its operand (most often, words separated by spaces) and reads them in a simple quotish context. Put a simpler way, qw(A $b C %h); could also be written ('A', '$b', 'C', '%h'). In Ruby there is a qw-like construct that allows double-quotish interpretation, but this is Perl. So you instead have to write use lib ("$some_path/lib",); (the comma is optional, I just always put an extra comma in a single element list).

The second issue is that use is called straightaway, so you could say that perl reads your program :

# Compiling using File::Spec using File::Basename there is a global variable called $some_path add to path $some_path/lib _Compilation complete_ # Running $some_path = dirname(File::Spec->rel2abs(__FILE__));
This is of course really simplified.

The BEGIN keyword means that a block has to be executed during compile time, and not to wait after compilation completion. You should write:

my $some_path; BEGIN { $some_path = "/my/path"; } use lib "$some_path/lib"; # Yeah, you don't even need the parenthesis, + Perl is clever enough for you # Edit : thanks dave_the_m for the correction

Replies are listed 'Best First'.
Re^4: use lib statement with path variable
by chromatic (Archbishop) on Dec 04, 2013 at 20:15 UTC
    Yeah, you don't even need the parenthesis, Perl is clever enough for you...

    You never need the parentheses there, unless you're doing something strange with precedence or associativity. A list is a list is a list.

      Indeed, I can't tell why I used parentheses in the first place actually ...

Re^4: use lib statement with path variable
by dave_the_m (Prior) on Dec 04, 2013 at 21:22 UTC
    You should write: ...
    The use statement needs to be outside the BEGIN block, e.g.
    my $some_path; BEGIN { $some_path = "/my/path"; } use lib "$some_path/lib";

    Dave.

      Thanks, corrected :)

Re^4: use lib statement with path variable
by sans-clue (Beadle) on Dec 05, 2013 at 03:47 UTC
    Muy bueno !!! Thanks so much

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1065644]
help
Chatterbox?
[LanX]: damn my headphones were not plugged and the video blasted thru the office ...
[LanX]: xD
[LanX]: .. my boos woke up... ;-)
[Eily]: nice to see I'm not the only one looking like a fool at work
Eily answered a message but made the smiley on his face instead of in the message

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2017-09-20 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (237 votes). Check out past polls.

    Notices?