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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:14:15+00:00 2026-05-26T20:14:15+00:00

I have a module with a set of functions implemented as a dispatch hash

  • 0

I have a module with a set of functions implemented as a dispatch hash with a helper function thus:

my $functions = {
  'f1' => sub { 
      my %args = @_;
      ## process data ...
      return $answer; 
  },
[etc.]
};

sub do_function {
    my $fn = shift;
    return $functions->{$fn}(@_);
}

This is used by some scripts that process tab-delimited data; the column being examined is converted by the appropriate subroutine. When processing a value in a column, I pass a hash of data to the sub, and it generates a scalar, the new value for the column.

Currently the subs are called thus:

my $new_value = do_function( 'f1', data => $data, errs => $errs );

and the variables in the arguments are all declared as ‘my’ – my $data, my $errs, etc.. Is it possible to update other values in the arguments that are passed into the subs without having to return them? i.e. instead of having to do this:

 ... in $functions->{f1}:
      my %args = @_;
      ## process data ...
      ## alter $args{errs}
      $args{errs}->{type_one_error}++; 
      ## ...
      return { answer => $answer, errs => $args{errs} }; 
 ...

 ## call the function, get the response, update the errs
 my $return_data = do_function( 'f1', data => $data, errs => $errs );
 my $new_value = $return_data->{answer};
 $errs = $return_data->{errs}; ## this has been altered by sub 'f1'

I could do this:

  my $new_value = do_function( 'f1', data => $data, errs => $errs );
  ## no need to update $errs, it has been magically updated already!
  • 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-26T20:14:15+00:00Added an answer on May 26, 2026 at 8:14 pm

    You can pass reference to value and update it inside of subroutine.

    For example:

    sub update {
        my ($ref_to_value) = @_;
        $$ref_to_value = "New message";
        return "Ok";
    }
    
    my $message = "Old message";
    
    my $retval = update(\$message);
    
    print "Return value: '$retval'\nMessage: '$message'\n";
    

    And as far as I can see from your code snippets, $errs is already reference to hash.
    So, actually, all you have to do – just comment out line $errs = $return_data->{errs}; and try

    If I get your code right, $errs gets updated. And then you should just change your return value to $answer and do:

    my $new_value = do_function( 'f1', data => $data, errs => $errs );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have enabled the lighttpd mod_webdav module and set up a webdav mount point
I have a python logger set up, using python's logging module. I want to
I have a module that reads the StandardError of a process. Everything works fine,
I have a custom form implemented in a custom module in drupal 6. The
So, I'm confused. I have a module containing some function that I use in
I have begun writing my 'class' type JavaScript functions like the Module Pattern or
I have implemented a drupal module to toggle two themes according to server time.
Let's say you have a Fortran 90 module containing lots of variables, functions and
I have module application. When I run it, the main window of that app
I have module that implements custom content type via NodeAPI hooks ( hook_insert ,

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.