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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:05:02+00:00 2026-05-22T18:05:02+00:00

I don’t exactly know how to state my problem below in a question so

  • 0

I don’t exactly know how to state my problem below in a question so please bear with me.

The problem:

I have a multi-dimension array that looks like this:

$raw_list[0]['123','foo','foo1','300']
$raw_list[1]['456','foo2','foo3','4']
$raw_list[2]['123','foo4','foo5','67']
$raw_list[3]['456','foo6','foo7','34']

This usually gets very large (can possibly get to over a thousand indexes?)

What I want to do with it is to separate all records with the same 0th element value in $raw_list[nth][0] and operate on each group such that…

$raw_list[0]['123','foo','foo1','300']
$raw_list[2]['123','foo4','foo5','67']

Then I operate on this group to get various statistical info. For example, the sum of element values ‘300’ and ’67’ and so on.

Current solution:

At the moment this is how my code actually looks like.

my @anum_group = ();
@die_raw_list = sort {$a->[0] <=> $b->[0]} @die_raw_list;

my $anum_reference = @die_raw_list[0][0];

for my $row (0..$#die_raw_list) 
{
    if ($die_raw_list[$row][0] == $anum_reference)
    {
        push @anum_group, $die_raw_list[$row];
    }
    else
    {
        # Profile ANUM group
        # ... operation to get statistical info on group here


        # Initialize next ANUM group
        $anum_reference = $die_raw_list[$row][0];
        @anum_group = ();
        push @anum_group, $die_raw_list[$row];
    }
}

# Profile last ANUM group
#  ... operation to get statistical info on group here

Final thoughts and question:

I realized that on very large data this tends to be very slow and I want to speed things up.

I’m new with Perl and don’t know how to best solve this problem.

  • 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-22T18:05:02+00:00Added an answer on May 22, 2026 at 6:05 pm

    A thousand indexes is not that many… What makes you think your code is slow? And what part is slow?

    If the first element is that important, you could re-arrange your data structure to index it that way in the first place:

    my %raw_list = ('123' => [['foo', 'foo1', '300'],
                              ['foo4', 'foo5', '67']],
                    '456' => [['foo2', 'foo3', '4'],
                              ['foo6', 'foo7', '34']]);
    

    You could build it dynamically something like this:

    my %raw_list;
    my $elt0 = '123';
    my @rec = ('foo', 'foo1', '300');
    push @{$raw_list{$elt0}}, \@rec;
    

    And process it like this:

    foreach my $elt0 (keys %raw_list) {
        my $records = $raw_list{$elt0};
        foreach my $rec (@$records) {
            # Now $elt0 is (e.g.) '123'
            # and $rec->[0] is 'foo', $rec->[1] is 'foo1', $rec->[2] is '300'
        }
    }
    

    To be really clean, you would want to encapsulate all of this in an object…

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

Sidebar

Related Questions

Don't let below code scare you away . The question is really simple, only
Don't exactly know what to search for: If i edit text in vim it
Don't yell at me! i have seen many threads claiming that HTML cannot be
I don't know when to add to a dataset a tableadapter or a query
I don't know if anyone has seen this issue before but I'm just stumped.
Don't you hate it when you have class Foobar { public: Something& getSomething(int index)
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know a whole lot about streams. Why does the first version work using
Don't know if this is the right place to ask this, but I will
Don't know whether I'm having a "thick day" - but I just wondered what

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.