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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:40:22+00:00 2026-05-27T19:40:22+00:00

I have two excel files. The first excel file is like this: 12 A

  • 0

I have two excel files. The first excel file is like this:

12   A    P1  
23   B    P5
24   C    P2
15   D    P1
06   E    P5

The second excel file is like this:

06 100
23 20
06 200
06 95
23 05
24 18

I want to generate the following data structure

$VAR1 = {
  'P5' => {
    'E' => '06' => [100, 200, 95]
    'B' => '23' => [20, 1000, 05, 30]
      },
      'P2' => {
        'C' => '24' => [18, 23, 2300, 3456]
  },
      'P1' => {
        'A' => '12' => [24, 25, 3200, 5668]
        'D' => '15' => [168]
      }
};

The first excel file enables me to generate the following data structure.

 $VAR1 = {
   'P5' => {
     'E' => '06',
     'B' => '23'
    },
    'P2' => {
      'C' => '24'
    },
    'P1' => {
      'A' => '12',
      'D' => '15'
    }
  };

What I did for implementing the above partial structure from the first excel file is as follows:

my %Var1;
for my $i (1 .. $row1)
{
    # for simplicity, I just keep the main part to building this hash chain
    $Var1{$column3}->{$column2} = {$column1};  
}                

Here $column3 relates to p1, p2, etc; $column2 relates to E, B, etc and $column1 relates to 06,23,24,etc. The arrays associated with $column1 will be extracted from the second excel file.

My question is how to iterate through this partially finished hash %Var1, and for each key, like 06, to push 100 into it while traversing the second excel file.

  • 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-27T19:40:23+00:00Added an answer on May 27, 2026 at 7:40 pm

    So, assuming (what im calling the numeric key ( the ’06’ in this example ) ) is unique then perhaps a function which returns the arrayref:

    sub get_arrayref_from_nkey {
        my $target = shift;
        for my $pkey ( keys %Var1 ) {
            for my $akey ( keys %{ $Var1{$pkey} } ) {
                for my $nkey ( keys %{ $Var1{$pkey}->{$akey} } ) {
                    if ( $nkey eq $target ) {
                        # return the arrayref to [ 100, 200, 95, .. ]
                        return @{ $Var1{$pkey}->{$akey}->{$nkey} };
                    }
                }
            }
        }
    }
    
    my $arrayref = get_arrayref_from_nkey('06');
    push @{ $arrayref }, $value;    # 100
    

    If the numeric key isn’t found the function will return undef. Also if the numeric key isn’t unique then this won’t work – because it will return the first nkey it finds.

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

Sidebar

Related Questions

I have two excel files. First excel file contains the Person Name and Total
I have two columns in Excel, like this: A B 0.5 0.4 0.6 0.59
I have a Excel CSV files with employee records in them. Something like this:
I have an Excel file Country.xls. This Excel file contains two sheet/records Country and
currently, I am struggeling with the following: I have two Excel files. One files
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two lists of names in Excel '07. Two columns in each file:
I have an requirement of generating two excel files at once. We are using
I have an excel spreadsheet with two columns. The first column is a label
I have a Word document with two embedded Excel files (added using Insert ->

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.