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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:55:23+00:00 2026-05-11T16:55:23+00:00

I have a function that takes a variable and an associative array, but I

  • 0

I have a function that takes a variable and an associative array, but I can’t seem to get them to pass right. I think this has something to do with function declarations, however I can’t figure out how they work in Perl. Is there a good reference for this and how do I accomplish what I need?

I should add that it needs to be passed by reference.

sub PrintAA
{
    my $test = shift;
    my %aa   = shift;
    print $test . "\n";
    foreach (keys %aa)
    {
        print $_ . " : " . $aa{$_} . "\n";
        $aa{$_} = $aa{$_} . "+";
    }
}
  • 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-11T16:55:23+00:00Added an answer on May 11, 2026 at 4:55 pm

    Pass the reference instead of the hash itself. As in

    PrintAA("abc", \%fooHash);
    
    sub PrintAA
    {
      my $test = shift;
      my $aaRef = shift;
    
      print $test, "\n";
      foreach (keys %{$aaRef})
      {
        print $_, " : ", $aaRef->{$_}, "\n";
      }
    }
    

    See also perlfaq7: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?

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

Sidebar

Ask A Question

Stats

  • Questions 523k
  • Answers 523k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can get it "half working" in the simpler case… May 16, 2026 at 9:35 pm
  • Editorial Team
    Editorial Team added an answer Inserting n items into a priority queue will have asymptotic… May 16, 2026 at 9:35 pm
  • Editorial Team
    Editorial Team added an answer When the iPhone is rotated, usually the affine transformation matrix… May 16, 2026 at 9:35 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a PHP function that takes a variable number of arguments (using func_num_args()
I have a function that takes a variable number of arguments in C that
I have a function that takes a list and replaces some elements. I have
I am porting Excel VBA to VB.NET. I have a function that takes a
I have a function that takes a ref parameter and would like to use
I have a function, ranker , that takes a vector and assigns numerical ranks
I have a function which must return one dimensional associate array, like $user_info[$index]=value where
Here's the story... I have a jQuery function that does something, this function is
I have this javascript function I am trying to understand. I don't know if
How can I make the code below into a function? # split the string

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.