Refers to the hash variable type in Perl. Other languages call this a dictionary or associative array.
Questions tagged [perl-hash]
71 questions
0
votes
2 answers
How to parse multiple csv files with Perl and print only the unique results
I have a bunch of csv file in a simple format say 'Name,Country,Currency'. I need to read all of them and print only the unique union. If they show up in few files they are identical. Tried to use Hash::Merge but seems to be working only for two. I…

rolleikid
- 13
- 2
0
votes
2 answers
How can I store one element of a two dimensional in another hash?
I have a two dimensional hash.
myHash = (
'a' => {
'a1' => v1
'a2' => v2
}
'b' => {
'b1' => v3
'b2' => v4
}
);
I want to retrieve a hash like this:
%hashSlice = %Hash{'a'};
Where hashSlice should…

Vishrut Maheshwari
- 19
- 3
0
votes
2 answers
Find average of hash values Perl
I am looking to return an average of the hash values (per key) below (grades.txt)
Melotti, Suzanne: 100 100 95 95 92 87
Wayne, Bruce: 85 85 85 75 75 75
Stark, Tony: 92 92 75 79 91 87
Odinson, Thor: 23 12 10 42 50 64
Kane, Kathy: 100 100 100 100 95…

dollarbin
- 19
- 3
0
votes
2 answers
How do I merge two hashes that start with different keys in Perl?
I have to hashes as follows:
my %hash1 = (
'modules' => {
'top0' => {
'instances' => {
'sub_top' => {
'instances' => {
'inst2' => 2,
'inst0'…

Vishwasu Deshpande
- 59
- 6
0
votes
3 answers
How can I iterate through nested hash of hash without knowing its key?
I have a hash of hashes, that is, hash and hash references in my data structure. Can I iterate through the deepest hash when I only have the main hash name and no key of the deepest hash?
my %gates_info=(
'order' => {
'nand' => {
…

P_Z
- 199
- 2
- 8
0
votes
1 answer
Accessing and printing Hash of array
I have a question of how to print a hash:
@language(1,2,3);
for my $i (0 .. $#language)
{
$statement = $db->selectall_arrayref(
"select word from words
left outer join language
on words.languageId = language.languageId
where…

JoT
- 301
- 1
- 3
- 10
0
votes
2 answers
How to access a nested hash of arrays in a loop?
I have data in this format
a1 1901 4
a1 1902 5
a3 1902 6
a4 1902 7
a4 1903 8
a5 1903 9
I want to calculate the cumulative score (3rd column) for each entity in the first column. So I tried to make a hash and my code looks like this:
use strict;
use…

swati sinha
- 7
- 2
0
votes
2 answers
Merging N no of files based on their first column in perl
My question is similar to this question posted earlier.
I am having many files which I need to merge them based on the presence or absence of the first column ID, but while merging I am getting lots of empty values in my output file, I want those…

Kanhu
- 39
- 5
0
votes
1 answer
In a hash, can we have three keys combined together that point to one value?
I have a doubt in the below hash declaration:
%metadataHash is a hash
line 1: $metadataHash->{"name"} = $name;
line 2: $metadataHash->{"type"} = $Type;
line 3: $metadataHash->{"student"}{$file}{"math"} = "/$file";
line 4:…

bioinforesearch
- 427
- 1
- 4
- 8
0
votes
2 answers
Callback for hash property access in perl
Is there any native way in Perl to know what key of a hash was accessed?
Something like magic methods that exist in some languages or like a proxy object?

eltonkamami
- 5,134
- 1
- 22
- 30
0
votes
2 answers
Perl hashes with value as array
I have an input file like below:
start
f1="apple"
f2="banana"
f3="berry"
end
start
f1="guava"
f2="banana"
f3="berry"
end
start
f1="apple"
f2="cucumber"
f3="orance"
end
I am planning to create a hash with values as arrays.
All the tags will be in a…

user1939168
- 547
- 5
- 20
0
votes
1 answer
How to sort this custom hashes of hashes in perl on the value
I am facing an issue with the sort functionality on my Application. I need to sort my Hash of hashes on the lname key under the instructors. The legacy
application is written in Perl.
Here is the dump of the Hash which i need to sort.
$VAR1 = {
…

Ash_and_Perl
- 356
- 5
- 21
0
votes
2 answers
Adding lists of key/values to an existing hash
I can initialize a hash from a list, e.g:
my %hash = (1..10);
my %hash2 = split /[\n=]/;
Is there a better (briefer) way to add lists of new key/values to a hash than using temporary variables?
while (<>) {
my ($k, $v) = split /=/, $_, 2;
…

RobEarl
- 7,862
- 6
- 35
- 50
0
votes
1 answer
Hierarchical configuration file in perl
I am writing a test automation software in perl and I came across a problem with the configuration files I defined.
The automation software receives an input CFG file written in perl hash that among other things defines the images to build.
Now…

Strudle
- 331
- 2
- 5
- 14
-1
votes
1 answer
correction of a faulty hash
Hello my fellow keyboard artists,
I wrote a code that reads a my_hash_data.txt file and looks a specific value (i-signal) and saves its parents key in i-signal-output.txt, which works good so far with the hash testfile i've created.
now i should use…

Xandl
- 21
- 4