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 8302557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:19:09+00:00 2026-06-08T17:19:09+00:00

i trying yo doing the the following pseudocode in perl #!/usr/bin/perl -w #App.pm use

  • 0

i trying yo doing the the following pseudocode in perl

#!/usr/bin/perl -w
#App.pm

use strict;
use OtherModule;
use Other2Module;

sub App::hashF
{
  my $hash_funtion = {
    'login' => OtherModule::login,
    'logout' => Other2Module::logout
  };

  my($module, $params) = @_;

  return $hash->{$module}($params);
}

but i get error like:
– Can’t use string (“login”) as a subroutine ref while “strict refs”
– Can’t use bareword (“OtherModelo”) as a HASH ref while “strict refs”

  • 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-08T17:19:10+00:00Added an answer on June 8, 2026 at 5:19 pm

    I decided to enhance your code:

    #!/usr/bin/perl
    #App.pm
    
    use strict; use warnings;
    
    package App;
    
    use OtherModule;
    use Other2Module;
    
    my $hash = {
      login  => \&OtherModule::login,
      logout => \&Other2Module::logout,
    };
    
    sub hashF
    {    
      my($module, @params) = @_;
    
      return $hash->{$module}->(@params);
    }
    

    We cannot assign bare names, but we can pass around code references. The & Sigil denotes the “code” type or a subroutine, and \ gives us a reference to it. (Not getting a reference would execute the code; not something we want. Never execute &subroutine unprovoked.)

    BTW: Hashes can only hold scalar values, and (code) references are a kind of scalar.

    When we want to call our sub from the hash, we have to use the dereference operator ->.
    $hash->{$module} returns a code reference as value; ->(@arglist) executes it with the given arguments.

    Another BTW: Don’t write App::hashF unless you are working inside an external module. You can declare your current namespace by writing package App or whatever name you like (should correspond with path/name of .pm file).

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

Sidebar

Related Questions

I am trying to throw exceptions and I am doing the following: use Symfony\Component\HttpKernel\Exception\HttpNotFoundException;
I'm trying to check a checkbox, i've tried doing the following :- $('#someId').attr('checked','checked'); $('#someId').attr('checked',
I am trying to parse the following JSON string remotely: [{name:Object1,data:[1,2]},{name:Object2,data:[3,4]}] I am doing
I've been trying to look in the wiki about doing this, I'm following it,
I'm trying to scale down a Bitmap using GDI+ by doing the following: Bitmap
I am trying to create an id for an input by doing the following
I am trying to figure out a cleaner way of doing the following: import
I am trying to use regular expressions to parse a method in the following
I am trying to pass an exception to an HttpHandler by doing the following:
I'm trying to figure out the best way of doing the following: I have

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.