in reply to Loading Modules At Run-Time With Interpolation

Backslash the first colon within double quotes. Also, after eval, check for $@, not $!. E.g.:

eval "require Foo\::$_" || die $@;

Update: On closer inspection, the lack of backslash is not a problem (I was thinking of pitfalls like "$foo::$bar"; but do check for $@ after eval!). FWIW, your code works fine for me.

# Foo/Quux.pm package Foo::Quux; print 'Loading ', __PACKAGE__, "\n";

use strict; use warnings; for ( 'Quux' ) { eval "require Foo::$_" || die $@; } __END__ Loading Foo::Quux

the lowliest monk

Replies are listed 'Best First'.
Re^2: Loading Modules At Run-Time With Interpolation
by Cody Pendant (Prior) on Aug 12, 2005 at 04:09 UTC
    FWIW, your code works fine for me.

    Sorry, I should have been more specific. It doesn't die when I do it, but it doesn't work as I expect it to. I'll add it my example code to the original post.



    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print