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

  • SEARCH
  • Home
  • 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 7167471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:35:02+00:00 2026-05-28T14:35:02+00:00

I have a hash table generated which I am then trying to add to

  • 0

I have a hash table generated which I am then trying to add to a larger hash table, (if unique) for each of multiple files but I’m having trouble with the syntax and keep accidentally calling values or creating a hash of hash. All I want to do is turn:

(The actual $hash key) => $hash{$key};

into

 $compound_hash{$key} = $hash{$key};

Currently I have:

    if ($file_no == 0){
            while (my ($key, $value) = each %hash){
                    $compound_hash{$key} = $value;
            }       

    }else{
            while (my ($key, $value) = each %compound_hash){

                    if (exists $hash{$key}){
                            print "$key: exists\n";
                            $compound_hash{$key} .= ",$hash{$key}";
                    }else{
                          print "$key added\n";  
                          XXXXXXX
                    }

The end result is to concatenate the hash value on to the end of each line, making a .csv ie

     abc,0,32,45
     def,21,43,23
     ghi,1,49,54
  • 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-28T14:35:03+00:00Added an answer on May 28, 2026 at 2:35 pm

    Its hard to tell exactly, but I think what you are looking for is something like this:

    for my $key (keys %hash) {  # for all new keys
         if (exists $compound_hash{$key}) {  # if we have seen this key
              $compound_hash{$key} .= ",$hash{$key}"  # append it to the csv
         }
         else {
              $compound_hash{$key} = $hash{$key}  # otherwise create a new entry
         }
    }
    

    In my own code, I might setup %compound_hash to be initially populated with array references, which are then joined down to strings once the data is filled.

    for my $key (keys %hash) {
         push @{ $compound_hash{$key} }, $hash{$key}
    }
    

    and then later

    for my $value (values %compound_hash) {
        $value = join ',' => @$value
    }
    

    Which will be more efficient than repeatedly appending data to the strings contained in the compound hash.

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

Sidebar

Related Questions

What I can think of is: Algo: Have a hash table which will store
I have a hash table where the keys are rather complex lists, with sublists
So if I have to choose between a hash table or a prefix tree
Lets say that I have only DHT (distributed hash table) implemented (in Python), and
I have a table of web pages, with the primary key as hash of
I have a large and unique integer (actually a SHA1 hash). Note: While I'm
I have a directory in which I have 1000 txt.files in it. I want
I have a html table that is generated by looping through DB entries. On
I have a table with a column of unique string values. The max length
I have often heard people talking about hashing and hash maps and hash tables.

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.