Your skill will accomplishwhat the force of many cannot PerlMonks

### Re^2: Hash user input

by Nansh (Acolyte)
 on May 24, 2017 at 18:44 UTC Need Help??

in reply to Re: Hash user input
in thread Hash user input

But it is treating both the hash as a single hash.

Replies are listed 'Best First'.
Re^3: Hash user input
by thanos1983 (Parson) on May 24, 2017 at 19:10 UTC

Hello Nansh,

As stevieb and Anonymous Monk proposed some possible solutions to your problem, your answer does not really help.

What I mean is your main goal, what are you trying to achieve? Do you want to pass two hashes inside a subroutine, you have already a solution on this. You want to pass the STDIN as parameters, you have an answer again.

So what you really want to do, we are still not able to understand.

Seeking for Perl wisdom...on the process of learning...not there...yet!
Re^3: Hash user input
by thanos1983 (Parson) on May 25, 2017 at 09:08 UTC

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!

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1191131]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-05-26 18:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found