Load perl module dynamically (use $object)

Discussion in 'Perl Misc' started by Markus Dehmann, Mar 5, 2006.

  1. Can I load perl modules dynamically?

    In other words, I want to do something like this:

    my $obj = "Getopt::Long";
    eval{ use $obj } or die($@);

    But it doesn't work like that. Is such a dynamic module loading possible
    at all?

    Markus
     
    Markus Dehmann, Mar 5, 2006
    #1
    1. Advertising

  2. Christian Winter wrote:

    > (my $pkg = $package) =~ s|::|/|g; # require need a path
    > require "$pkg.pm";


    See also UNIVERAL::require
     
    Brian McCauley, Mar 7, 2006
    #2
    1. Advertising

  3. Brian McCauley wrote:
    > Christian Winter wrote:
    >
    > > (my $pkg = $package) =~ s|::|/|g; # require need a path
    > > require "$pkg.pm";

    >
    > See also UNIVERAL::require


    That should, of course, say UNIVERSAL::require
     
    Brian McCauley, Mar 7, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nancy Sui
    Replies:
    1
    Views:
    2,587
    Scott Allen
    Nov 30, 2004
  2. =?Utf-8?B?UmV6YSBOYWJp?=

    Load User Control Dynamically, Cast object dynamically

    =?Utf-8?B?UmV6YSBOYWJp?=, Mar 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    6,808
    Matt Berther
    Mar 5, 2005
  3. =?Utf-8?B?UmV6YSBOYWJp?=

    Load User Control Dynamically, Cast object dynamically

    =?Utf-8?B?UmV6YSBOYWJp?=, Mar 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    6,376
    Scott Allen
    Mar 4, 2005
  4. Maric Michaud
    Replies:
    0
    Views:
    7,212
    Maric Michaud
    Jun 24, 2006
  5. Replies:
    2
    Views:
    528
    Paul Lalli
    Feb 6, 2006
Loading...

Share This Page