You have a second problem.
$day = "sunday"; $userId= "mary"; BEGIN { push (@INC, "./dir_$day"); } ...
is processed as follows:
As you can see, $day is only given a value long after the BEGIN block uses them. It always amazes me that people are willing to come to PerlMonks to find a problem with their code when use warnings; would have told them. The two most useful tools:
use strict; use warnings;
Solution:
my $userId= "mary"; BEGIN { my $day = "sunday"; push (@INC, "./dir_$day"); } ...
All together:
#!/usr/bin/perl use strict; use warnings; BEGIN { my $day = "sunday"; my $userId = "mary"; push (@INC, "./dir_$day"); eval "use module_$userId qw( ); 1" or die $@; *diary = \%diary::diary; }
It doesn't make much sense to specify %diary on the use line do the alias via an assignment. That means the %diary on the use line is being ignored. You can fix that by using Exporter. Then you'd replace the last two lines with:
eval "use module_$userId qw( %diary ); 1" or die $@;
By the way, please don't include line numbers in posted code. We are quite able to count to fifteen. All it does is make it very hard to cut and paste.
In reply to Re: How to use variables in @INC and "use" commands
by ikegami
in thread How to use variables in @INC and "use" commands
by Arun Tv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |