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 8908111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:05:45+00:00 2026-06-15T03:05:45+00:00

How can i merge multiple CSV files in perl? For example I have file

  • 0

How can i merge multiple CSV files in perl?

For example I have file 1 Packet1.csv looking like:

#type, number, info, availability
computer, t.100, pentium 2, yes
computer, t.1000, pentium 3, yes
computer, t.2000, pentium 4, no
computer, t.3000, pentium 5, yes

and file 2 Packet2.csv looking like:

#type, number, info, availability
computer, t.100, pentium 2, yes
computer, t.1000, pentium 3, no
computer, t.2000, pentium 4, no
computer, t.4000, pentium 6, no

and the output i desire is a single file where the number of Packets is not fixed :

#type, number, info, **Packet1** availability, **Packet2** availability
computer, t.100, pentium 2, yes, yes
computer, t.1000, pentium 3, yes, no
computer, t.2000, pentium 4, no, no
computer, t.3000, pentium 5, yes
computer, t.4000, pentium 6, no
  • 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-06-15T03:05:46+00:00Added an answer on June 15, 2026 at 3:05 am

    Going back to your attempt at multidimensional hashing: Hash of hashes perl, you will need to change the data structure you are using in order to store multiple entries of a particular element.

    CSVs can be intuitively read in to a hash with 2 levels. The rows of the csv can be hashed by their IDs (in this case I guess the IDs are the numbers ‘t.100’, ‘t.1000’ etc) and the values of each row can be stored in the second level hash using the header strings as its keys. It will look something like this if you viewed the structure with Data::Dumper:

    $VAR1 = {
              't.1000' => {
                            'info' => 'pentium 3',
                            'availability' => 'yes',
                            'type' => 'computer'
                          },
              't.100' => {
                           'info' => 'pentium 2',
                           'availability' => 'yes',
                           'type' => 'computer'
                         }
            };
    

    Whether ‘number’ is also a key for each ‘row hash’ is up to you depending on how useful that might be (usually you already know the key for the row in order to access it).

    This data structure would be fine in order to store one CSV file. However we need to add an extra layer of complexity in order to cope with merging multiple CSVs in the way that you describe. For example, to keep track of the files that a particular ID appears in, we can store a third hash as the value of the ‘availability’ key, since that is the value that is changing between entries of the same ‘number’:

    'availability' => {
              'Packet1' => 'yes',
              'Packet2' => 'no'
            };
    

    Once all files have been read into this structure, printing the final CSV out is then a process of looping over the keys of the outer hash and, for each row, ‘joining’ the row’s keys in the correct order. The ‘Packet’ hash can also be looped over to retrieve all ‘availability’ values and these can be appended to the end of each row.

    I hope that helps you understand one possible way of dealing with this kind of data. You can ask about specific parts of the implementation if you are finding them difficult and I will be happy elaborate.

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

Sidebar

Related Questions

I have this simple example I can't seems to get working : MERGE INTO
I am looking to merge multiple xslt stylesheets (V1.0) into one stylesheet. I have
Is it possible to have multiple separate Canvas layers, which I can merge to
We have a issue where we are trying to merge persistence.xml files from multiple
I have around 100 csv files with common headers, which i want to merge.
I need to write a java application which can merge docx files. Any suggestions?
How can you get the number of affected rows from executing a MERGE INTO...
Currently, I can add the creator_id like this in my controller: @entry = Entry.new(params[:entry].merge(:creator
There are a lot of tutorials that show on how to merge multiple files
Is it possible to paqckage multiple rpms into one file. I have got two

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.