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

  • SEARCH
  • Home
  • 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 8112143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:22:49+00:00 2026-06-06T02:22:49+00:00

In Perl, you are able to call a function by reference (or name) like

  • 0

In Perl, you are able to call a function by reference (or name) like so:

    my $functionName = 'someFunction';
    &$functionName();

    #someFunction defined here:
    sub someFunction { print "Hello World!"; }

What I am trying to do is use a value from a Hash, like so:

    my %hash = (
        functionName => 'someFunction',
    );

    &$hash{functionName}();

    #someFunction defined here:
    sub someFunction { print "Hello World!"; }

And the error I get is Global symbol “$hash” requires explicit package name.

My question is: Is there a correct way to do this without using an intermediate variable?
Any help on this would be greatly appreciated!

  • 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-06-06T02:22:51+00:00Added an answer on June 6, 2026 at 2:22 am

    It’s just a precedence issue that can be resolved by not omitting the curlies. You could use

    &{ $hash{functionName} }()
    

    Or use the alternate syntax:

    $hash{functionName}->()
    

    As between indexes, the -> can be omitted (but I don’t omit it here):

    $hash{functionName}()
    

    Ref: Deferencing Syntax

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Perl module and I'd like to be able to pick out
I do not get to understand how the Perl read($buf) function is able to
Currently in my Perl script I make a call like the following: system( ./long_program1
I really like being able to use =~ and !~ in Perl to evaluate
I would like to be able to capture variable assignments from a Perl eval.
I want to be able to limit Perl's File::Find to a directory depth (below
In Perl, the array index -1 means the last element: @F=(1,2,3); print $F[-1]; #
I have php scripts that call perl scripts to do various things and sometimes
I need to be able to run a commandline command from my perl script
In Perl, we have IO::ScalarArray for treating the elements of an array like the

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.