Re: ADD directory to @INC using a string variable (not when variables initialized use BEGIN)
by Anonymous Monk on Sep 23, 2013 at 15:38 UTC
|
$ perl -E " $foo = 1; my $bar = 2; BEGIN{ say -WHAT,$foo,$bar; } say $
+foo,$bar; "
-WHAT
12
$ perl -wE " $foo = 1; my $bar = 2; BEGIN{ say -WHAT,$foo,$bar; } say
+$foo,$bar; "
Use of uninitialized value $foo in say at -e line 1.
Use of uninitialized value $bar in say at -e line 1.
-WHAT
12
$ perl -wE " my $bar; BEGIN{$foo = 1; $bar = 2;} BEGIN{ say -WHAT,$foo
+,$bar; } say $foo,$bar; "
-WHAT12
12
use happens at BEGIN time, lexicals(my variables) have no value at BEGIN time, lexicals(my) get initialized after BEGIN
But like I said, don't do that | [reply] [d/l] |
|
|
Thanks for the resources and links. I will take a look at them and see if I can make it work.
Regards,
Siddharth
| [reply] |
Re: ADD directory to @INC using a string variable
by jellisii2 (Hermit) on Sep 23, 2013 at 15:21 UTC
|
| [reply] |
|
|
Thanks for your response but I want to use the path in a string variable.
my $path = "/abc/xyz/bcd"
use lib $path;
it throws me the following error
Empty compile time value given to use lib at CWD/filename.pm
Thanks,
Sid
| [reply] |
Re: ADD directory to @INC using a string variable
by Laurent_R (Canon) on Sep 23, 2013 at 15:28 UTC
|
Try use lib hardcoded_path_name;. The use directives are executed at compile time, before the variables used in the code are set.
Else you could set your variable in a BEGIN block, just prior to using it.
| [reply] [d/l] |
|
|
I cannot use a hardcoded path, it is a varying path based on the user.
$path = user's cwd/somepath/filename.pm
Regards,
Siddharth
| [reply] |
|
|
use lib './somepath/';
or
BEGIN {
my $path = 'somepath';
push @INC, $path;
}
or why not just let the user set his/her PERL5LIB environment variable? | [reply] [d/l] [select] |
Re: ADD directory to @INC using a string variable
by CountZero (Bishop) on Sep 23, 2013 at 18:01 UTC
|
unshift @INC, $path;
Warning: this will only take effect at run-time, so any module loaded with use will not see this as use works at compile time.
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics
| [reply] [d/l] [select] |
|
|
So I can do a require in place of use and it should work correct?
Regards,
Siddharth
| [reply] |
|
|
Yes, that will work. But remember that require is not the same as use: the import sub will not be called
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics
| [reply] [d/l] [select] |
Re: ADD directory to @INC using a string variable
by toolic (Bishop) on Sep 23, 2013 at 15:28 UTC
|
- Show the code above your lib line.
- Show your exact error message in "code" tags.
| [reply] |
|
|
Empty compile time value given to use lib at /proj/zn_ver_user2/sidsh
+a/build_plugin/infra/lib/BuildPlugin.pm line 32.
Use of uninitialized value in require at /proj/zn_ver_user2/sidsha/bui
+ld_plugin/infra/lib/BuildPlugin.pm line 33.
Use of uninitialized value in require at /proj/zn_ver_user2/sidsha/bui
+ld_plugin/infra/lib/BuildPlugin.pm line 33.
Can't locate BuildPluginInc.pm in @INC (@INC contains: /proj/zn_ver_u
+ser2/sidsha/build_plugin/import/rndcfg/lib /proj/zn_ver_user2/sidsha/
+build_plugin/verif/lib /proj/zn_ver_user2/sidsha/build_plugin/infra/c
+onfig /proj/zn_ver_user2/sidsha/build_plugin/infra/lib /proj/verif_re
+lease_ro/vv/60/lib /proj/verif_release_ro/RegrPlatform/17/lib/perl /p
+roj/verif_release_ro/ubts_access/56/lib/perl /proj/verif_release_ro/S
+igSync/313/lib/perl /proj/verif_release_ro/s_trapbug/32/lib/perl /pro
+j/verif_release_ro/psm/22/tb /proj/verif_release_ro/dsm/43/tb /proj/v
+erif_release_ro/dfxcfg/3/lib/perl /proj/verif_release_ro/sql_utils/56
+/lib/perl/DBInsert /proj/verif_release_ro/sql_utils/56/lib/perl /proj
+/verif_release_ro/kx_core/1678/lib/perl /proj/verif_release_ro/kx_too
+ls/18/lib/perl /proj/verif_release_ro/patterndb/89/lib/perl /proj/ver
+if_release_ro/DatabaseKeywords/131/lib/perl /proj/verif_release_ro/cx
+shell/38/lib /proj/verif_release_ro/verif_modules/53/lib/perl /proj/v
+erif_release_ro/bt/project_tools/242/lib/perl /proj/verif_release_ro/
+utils/63/lib/perl /proj/verif_release_ro/siteconfig/current/lib/perl
+/proj/verif_release_ro/version_control/14/lib/perl /proj/verif_releas
+e_ro/software_stack/12/lib/perl /proj/verif_release_ro/regr_support/2
+9/lib/perl /proj/verif_release_ro/regr_stack/65/lib/perl /proj/verif_
+release_ro/regr_load_balancer/40/lib/perl /proj/verif_release_ro/regr
+_db_interface/102/lib/perl /proj/verif_release_ro/regr_config/109/lib
+/perl /proj/verif_release_ro/regr_cluster_interface/34/lib/perl /proj
+/verif_release_ro/crdb_api/117/lib/perl /proj/verif_release_ro/crdb20
+_db_interface/30/lib/perl /proj/verif_release_ro/crdb_db_interface/10
+5/lib/perl /proj/verif_release_ro/results_analysis/141/lib/perl /proj
+/verif_release_ro/job_specification/195/lib/perl /proj/verif_release_
+ro/dispatch/266/lib/perl /proj/verif_release_ro/flow_managers/106/lib
+/perl /proj/verif_release_ro/fm_verif_plugins/343/lib/perl /proj/veri
+f_release_ro/autosmoke/89/lib /proj/zn_ver_user2/sidsha/build_plugin/
+out/linux_2.6.18_64.VCS/common/pub/lib/perl /proj/zn_ver_user2/sidsha
+/build_plugin/out/linux_2.6.18_64.VCS/common/pub/bin /proj/verif_rele
+ase_ro/rgb_build/196 /proj/verif_release_ro/rgb/70 /proj/verif_releas
+e_ro/rgb/70/aleLexer/blib/lib /proj/verif_release_ro/leda_rules/2013.
+Q2p1_2013.03-03/lib /proj/verif_release_ro/drop2cad/94/lib/perl /proj
+/verif_release_ro/compression_utils/19/lib/perl /proj/verif_release_r
+o/ustat_send/27/lib/perl /proj/verif_release_ro/project_config/25/lib
+/perl /proj/verif_release_ro/p4w/223 /proj/verif_release_ro/cbwa/218/
+lib/perl /proj/verif_release_ro/xml_utils/47/lib/perl /proj/verif_rel
+ease_ro/p4_mkwa/current /proj/verif_release_ro/error_reporting/25/lib
+/perl /proj/verif_release_ro/cbwa_bootcore/current/lib/perl /tool/pan
+dora64/.package/perl-5.8.8/lib/5.8.8/x86_64-linux-thread-multi /tool/
+pandora64/.package/perl-5.8.8/lib/5.8.8 /tool/pandora64/.package/perl
+-5.8.8/lib/site_perl/5.8.8/x86_64-linux-thread-multi /tool/pandora64/
+.package/perl-5.8.8/lib/site_perl/5.8.8 /tool/pandora64/.package/perl
+-5.8.8/lib/site_perl .) at /proj/zn_ver_user2/sidsha/build_plugin/inf
+ra/lib/BuildPlugin.pm line 33.
BEGIN failed--compilation aborted at /proj/zn_ver_user2/sidsha/build_p
+lugin/infra/lib/BuildPlugin.pm line 33.
Compilation failed in require at /proj/verif_release_ro/rgb_build/196/
+build line 8.
BEGIN failed--compilation aborted at /proj/verif_release_ro/rgb_build/
+196/build line 8.
| [reply] [d/l] |
|
|
If you run that through splain you'll get
Empty compile time value given to use lib at /proj/zn_ver_user2/sidsh
+a/build_plugin/infra/lib/BuildPlugin.pm line 32.
Use of uninitialized value in require at
/proj/zn_ver_user2/sidsha/build_plugin/infra/lib/BuildPlugin.p
+m line 33 (#1)
(W uninitialized) An undefined value was used as if it were alread
+y
defined. It was interpreted as a "" or a 0, but maybe it was a mi
+stake.
To suppress this warning assign a defined value to your variables.
To help you figure out what was undefined, perl will try to tell y
+ou
the name of the variable (if any) that was undefined. In some cas
+es
it cannot do this, so it also tells you what operation you used th
+e
undefined value in. Note, however, that perl optimizes your progr
+am
anid the operation displayed in the warning may not necessarily ap
+pear
literally in your program. For example, "that $foo" is usually
optimized into "that " . $foo, and the warning will refer to the
concatenation (.) operator, even though there is no . in
your program.
I explain /demonstrate why its uninitialized in Re: ADD directory to @INC using a string variable (not when variables initialized use BEGIN)
But I really just wanted to respond to say eew at your 60-entries of @INC, because whatever your reasons, 60-deep-@inc is eew :) | [reply] [d/l] |
Re: ADD directory to @INC using a string variable
by Laurent_R (Canon) on Sep 23, 2013 at 15:54 UTC
|
Assuming you are on some form of Un*x, can you use something like this:
use lib '~/some_path/';
BTW, the argument after lib should be a path.
| [reply] [d/l] |
|
|
can I use a string variable instead ??
something like use lib $path
Regards,
Siddharth
| [reply] |
Re: ADD directory to @INC using a string variable
by Anonymous Monk on Sep 24, 2013 at 13:30 UTC
|
| [reply] |