Hello again

Why I still believe that your question in not answered?

Although the rest of the monks they have replied to your question in a variety of ways stating more or less the same I think you are getting confused on how the parameters are passed on the subroutine. Correct if I am wrong but I think you are getting confused about the @_ in the subroutine why there is only one and not two correct?

Sample of code taken from (perlsub/Pass by Reference) with minor modifications:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash_1 = (a => 26, b => 2, c => 3); my %hash_2 = (z => 26, y => 25); my ($ahashref, $bhashref) = func(\%hash_1, \%hash_2); print Dumper $ahashref, $bhashref; sub func { my ($cref, $dref) = @_; if (keys %$cref > keys %$dref) { return ($cref, $dref); } else { return ($dref, $cref); } }

I use (Data::Dumper) for debugging purposes to analyze the @_. Sample of the output from the example provided above:

print Dumper \@_; $VAR1 = [ { 'b' => 2, 'a' => 26, 'c' => 3 }, { 'y' => 25, 'z' => 26 } ];

What you see here is an perldsc/ARRAYS OF HASHES. Maybe the perlsub/DESCRIPTION will help a bit more:

Any arguments passed in show up in the array @_ . (They may also show up in lexical variables introduced by a signature; see Signatures below.) Therefore, if you called a function with two arguments, those would be stored in $_[0] and $_1 . The array @_ is a local array, but its elements are aliases for the actual scalar parameters. In particular, if an element $_[0] is updated, the corresponding argument is updated (or an error occurs if it is not updatable). If an argument is an array or hash element which did not exist when the function was called, that element is created only when (and if) it is modified or a reference to it is taken. (Some earlier versions of Perl created the element whether or not the element was assigned to.) Assigning to the whole array @_ removes that aliasing, and does not update any arguments.

If still your question is not answered let us know.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re^3: Hash user input by thanos1983
in thread Hash user input by Nansh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.