Hi, I want to import some perl modules inside a program.
I have many perl modules (say module_john.pm, module_kevin.pm, module_mary.pm)
in all the following directories: ./dir_sunday, ./dir_monday, ./dir_friday etc..
While running the program I am not able to specify which perl module (in which dir) I want to choose.
How can I use variables in "use" and "@INC" statements ?
My Program is given below.
========================== 1 #!/usr/bin/perl 2 3 $day = "sunday"; # This input is expected from the user while +running. 4 $userId= "mary"; # This input is expected from the user while +running. 5 6 BEGIN { 7 push (@INC, "./dir_$day"); 8 } 9 10 $tmp = "module_".$userId; 11 12 use $tmp qw(%diary); # %diary is a hash in the perl module + ./dir_sunday/module_mary.pm 13 *diary = \ %diary::diary; 14 15 <Program body> ===================================
I am getting errors
"cant locate file module_mary.pm in @INC" and "Syntax error if I use $tmp in line No:12"

In reply to 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.