in reply to use lib problem.

Hey,

thank you all for your replies

It does seem a little weird. The part where I'm trying to execute my code is inside a sub routine that validates form fields. I only want to load Email::Valid if and only it needs to validate a e-mail field.

Anyhow, the code above worked out...however I do not wish to load it at runtime if I don't have to? Not sure if this is a good idea or not, if not , I'll just load it at runtime.

tanger

Replies are listed 'Best First'.
Re^2: use lib problem.
by shmem (Chancellor) on Jun 01, 2007 at 07:50 UTC
    If you want to conditionally load modules at runtime, you want require:
    sub validate_fields { ... if($q->param(mail)) { my $mod = '/home/tanger/www/mods'; unshift @INC, $mod unless $INC[0] eq $mod; require Email::Valid; # to include the code import Email::Valid; # to import symbols into your names +pace ... } ... }

    Read perlmod - I've done that again yesterday. It is good to re-read manual pages, since there are always things in them which escape your attention in the first place, but get important when your knowledge of perl deepens. Read the docs, and often! :-)

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re^2: use lib problem.
by friedo (Prior) on Jun 01, 2007 at 07:42 UTC
    Well, your use statements will get executed at compile-time whether the condition is true or not. To conditionally load a module at runtime, you can do this:
    if ( $want_to_check_email ) { unshift @INC, $mod_path; require Email::Valid; Email::Valid->import; }