Refers to the hash variable type in Perl. Other languages call this a dictionary or associative array.
Questions tagged [perl-hash]
71 questions
1
vote
3 answers
Inserting and iterating over hash of arrays
I have following input data
Country1:operator1
Country1:operator2
Country1:operator3
Country2:operator1
Country2:operator2
Country2:operator3
I would like to insert this data into hash %INFO such that every key corresponds to an array of…

libxelar.so
- 473
- 4
- 16
1
vote
2 answers
Perl Hash references to the hash values inside same hash
My requirement is as below. Inside the same hash the values of keys are dependent on other key value as shown below
my %test;
$test{map}{a} = 32;
$test{map}{b} = $test{map}{a}+10;
$test{ref}{r} = $test{map}{b};
So, when I do
print…

Ajatasatru
- 15
- 2
1
vote
1 answer
Cannot fire subroutine inside a hash of subroutines in perl
Hi I'm quite new to perl. I have a perl hash containing subroutines. I've tried to run it in various ways that I found online. But nothing seems to work.
My code :
%hashfun = (
start=>sub { print 'hello' },
end=>sub { print 'bye' }
);
And I've…

Ihsan Izwer
- 133
- 2
- 11
1
vote
1 answer
dereferencing nested hash perl
If I declare a hash like this:
my %n = (a => {1 => "1a",2 => "2a"},"b" => {1 => "1b",2 => "2b"});
How do I access the data in: n -> a -> 1?
I tried
print "$n{a{1}}";
print "$n{a ->{ 1}}";
These two don't work

Tapajit Dey
- 1,327
- 2
- 13
- 22
1
vote
1 answer
How to copy a nested hash
How to copy a multi level nested hash(say, %A) to another hash(say, %B)? I want to make sure that the new hash does not contain same references(pointers) as the original hash(%A).
If I change anything in the original hash (%A), it should not…

gsinha
- 1,165
- 2
- 18
- 43
1
vote
1 answer
Perl hash giving undef values
If was trying to write a piece of code using perl hash. There are no undefined values or new lines in __DATA__(tried giving same input from file also). But while printing using data dumper or the traditional way I am getting a '' as key and undef…

aravind ramesh
- 307
- 2
- 15
1
vote
1 answer
Accessing elements in hash of hash of arrays in perl
my %PlannedPerWeek = (
September => {
Week1 => [80, 23, 199, 45, 19, 36],
Week2 => [78, 21, 195, 43, 18, 36],
Week3 => [76, 19, 191, 41, 17,…

Ram
- 1,153
- 4
- 16
- 34
1
vote
3 answers
How do I assemble a hash of hashes piece-wise, not up-front?
I want to create a structure of hashes within hashes in Perl, but all tutorials (like chapter 9.4. Hashes of Hashes in Programming Perl) add them all upfront. I want to initially create the structure and then fill in the empty hashes using…

user1512947
- 11
- 1
0
votes
1 answer
Can't use string ("test_value") as a HASH ref while "strict refs" in use at main.pl line 23
Can't use string ("test_value") as a HASH ref while "strict refs" in use at main.pl line 23.
use strict;
use warnings;
my $config = {'%test_value' => {'value' => '1'}};
my $args = 'test_value';
print $$config{%$args}{'value'};
I'm trying…
0
votes
3 answers
Shorten code: merge arrays from hashes
I have a list of hashes and some of the hashes contain a key which provides an array itself.
my @cars = (
{ # empty car
name => "BMW",
},
{ # car with passengers
name => "Mercedes",
passengers => [qw(Paul Willy)],
},
…

Daniel Böhmer
- 14,463
- 5
- 36
- 46
0
votes
2 answers
Perl hash add values
I am trying to push values into hash. I want to add the values under 'par3'.
e.g.
$VAR1 = { 'obj1' => ['par1',
'par2',
'par3' => ['par4','par5','par6',....]]}
I should also be able to add elements into…

Dana
- 107
- 9
0
votes
1 answer
How to iterate through an Array of hashes in Perl?
I have the following array:
ifNameList -> $VAR1 = [
{
'VALUE' => ' gpon_olt-1/1/1',
'ASN1' => '285278465'
},
{
'VALUE' => ' gpon_olt-1/1/2',
'ASN1' => '285278466'
…

ExploitZ
- 13
- 5
0
votes
1 answer
How to convert Perl hash to JSON with Java?
I would appreciate a sample of Java code that converts Perl hash into JSON.
Lots of Perl code can do this, but so far unable to find an equivalent Java code.
Sample hash:
{
'connection' => {
'activate_on_startup' => 'y',
…

Ron Warshawsky
- 314
- 2
- 11
0
votes
2 answers
Initializing hash of arrays
I wanted to have a hash of arrays of counters, with initial values of 0.
Here is my first attempt at the code:
my @names = ("", a, b, c);
my %hsh = ();
for $i (1..3)
{
# I expected this line to give me a fresh new array each time - it did not.
…

T G
- 445
- 3
- 7
0
votes
1 answer
Perl: How to make hash of hash where keys come from an array
I want to make a hash of hash using the structure of an array. Each array element should be a subkey of the preceding array element. For example using the following arrays:
@array1 = ("animal","dog","sparky");
@array2 =…

Westrock
- 169
- 4
- 14