Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6940943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:49:15+00:00 2026-05-27T12:49:15+00:00

After studying the Perl require docs and other links like this on Stackoverflow I’m

  • 0

After studying the Perl require docs and other links like this on Stackoverflow I’m still none the wiser, must be missing a fairly simple trick. I’m loading a module at runtime and calling a subroutine in it. The problem is I don’t necessarily know the name of the exported subroutine, but there must be one and it is exported.

The modules all look like this, ie. they roughly follow a template taken from perlmonks.org

package modules::Test;

use strict;
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

$VERSION     = 1.00;
@ISA         = qw(Exporter);
@EXPORT      = (*TestSubSomeUnknownName);
@EXPORT_OK   = qw(&TestSubSomeUnknownName);
%EXPORT_TAGS = ( ALL => [qw(&TestSubSomeUnknownName)]
               );


sub TestSubSomeUnknownName
{
    # return a hash reference
}

Then I can access the sub like this, assuming I know its name:

use Module::Load;

my $package = "modules::Test";
my $subr = "TestSubSomeUnknownName";

load $package;
# Call the subroutine
my $hashref = $package->$subr;

But what if someone mis-spelled the name in a package or I don’t know it? The solution seems to be to use one of the EXPORTs to see what’s in there, but how can it be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:49:16+00:00Added an answer on May 27, 2026 at 12:49 pm
    • @EXPORT should contain names not symbols.
    • You don’t need the ampersand before the function name and it’s non standard.
    • Remember the to return 1 at the end of a module.
    • If you want to check what a package can do, use can.

      die 'Auto-import sub was not named "TestSubSomeUnknownName"' 
          unless  $package->can( 'TestSubSomeUnknownName' )
          ;
      $package->TestSubSomeUnknownName(); 
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a really elementary question. Nonetheless, I haven't found a solution after studying
After studying the docs for a while, I came up with my first jQuery
I am studying ASP.net MVC Framework. After I reading this article , I can
I look after a large site and have been studying other similar sites. In
After studying TCP/UDP difference all week, I just can't decide which to use. I
Even after studying the examples , I'm having trouble figuring out how to extract
After some studying, I created a small app that calculates DFTs (Discrete Fourier Transformations)
After reading the Head First Design Patterns book and using a number of other
After reading this question , I was reminded of when I was taught Java
After reading a bit more about how Gnutella and other P2P networks function, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.