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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:37:08+00:00 2026-05-30T09:37:08+00:00

My goal is to remove from the raw stack the records that are not

  • 0

My goal is to remove from the raw stack the records that are not in the good keys list.

How do I achieve this in the most efficient manner? The code I’m currently working on feels dragging. I’m open for suggestions.

Please do note that the values could get ridiculously large.

Here’s my data:

# Main data container
my %raw_stack = (
    'a1~a2~a3' => 'dat1~dat2',
    'b1~b2~b3' => 'dat1~dat2',
    'c1~c2~c3' => 'dat1~dat2',
    'd1~d2~d3' => 'dat1~dat2',
    'e1~e2~e3' => 'dat1~dat2',
);

# Container of stack keys only
my @stack_keys = (
    'a1~a2~a3',
    'b1~b2~b3',
    'c1~c2~c3',
    'd1~d2~d3',
    'e1~e2~e3',
);

# Container of valid keys
my @good_keys = (
    'a2',
    'c2',
    'e2',
);

Here’s the code I’m currently working on:

foreach my $good_key (@good_keys)
{
    foreach my $stack_key (@stack_keys)
    {
        my @stack = split(/~/, $stack_key);
        if ($stack[1] eq $good_key)
        {

        }
    }
}

I feel like there’s a way to not need the stack keys container. I just don’t know how…

  • 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-30T09:37:09+00:00Added an answer on May 30, 2026 at 9:37 am

    There is that favorite quote by Larry Wall: “Doing linear scans over an associative array is like trying to club someone to death with a loaded Uzi.”

    You should know about hash slices. With which you can do what’s below. Of course that implies that you have a list of exact keys, which you don’t. But to illustrate:

    my %clean_hash;
    @clean_hash{ @good_keys } = @raw_stack{ @good_keys };
    

    However if you don’t want to copy the values, you could do something a little more complicated like this:

    delete @raw_stack{ grep { $_ !~~ @good_keys } keys %raw_stack };
    

    This uses smart matching from 5.10.

    Of course you’ll have to adapt from that. Assuming that you are only looking at the middle key [1], it looks to me like you’re looking for a pattern in a key, so create one.

    my $regex = join( '|', sort { length( $b ) <=> length( $a ) or $a cmp $b } @good_keys );
    $regex    = qr{~($regex)~};
    delete @raw_stack{ grep { !m/$regex/ } keys %raw_stack };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal is to remove home from any actions in that controller (see bold).
My goal is to remove all <[script]> nodes from a document fragment (leaving the
I'm implementing the A* search algorithm from this pseudo on wikipedia's article: function A*(start,goal)
My goal is to convert list into array using split method then remove element(depends)
I'm trying to remove relationships from a pivot table with ORM's remove method. This
My goal is to remove all hover feedback from the UI. The motivation is
Goal: I'm trying to refresh content inside a div so that if the user
Goal: json_encode a PHP object that has private properties Send the encoded object as
My Basic Goal A Rails app that can load new content via Ajax while
Does anybody see any drawbacks? It should be noted that you can't remove anonymous

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.