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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.