The problem is that use calls are evaluated at BEGIN time, while your lexical variable declarations are called after that. Although use lib LIST does not try to import a module, it's still a compile-time pragma, and to my knowledge, those are still evaluated at BEGIN time.

So, I recommend trying this:

my $mod_path; # or @mod_path, if you're so inclined. BEGIN { $mod_path = '/home/ripenapp/perl_mods'; } use lib $mod_path; use Email::Valid;

What this does is ensure that a value is assigned in $mod_path before use lib $mod_path is called -- as use calls are implicitly wrapped in BEGIN blocks (see use and lib) and BEGIN blocks are executed sequentially in the order of definition (see perlmod).

By the way, you do use strict, right? use lib $mod_path ought to complain in your example code, as the variable hasn't been assigned a value before use lib is called...

--
print "Just Another Perl Adept\n";


In reply to Re: use lib problem. by vrk
in thread use lib problem. by tanger

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.