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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:18:17+00:00 2026-05-13T23:18:17+00:00

there is a set of data which is arranged in a specific manner (as

  • 0

there is a set of data which is arranged in a specific manner (as a tree), as is given below. basically a key=value pair, with some additional values at the end, which informs how many children does the branch have and some junk value.

11=1 123 2
11=1>1=45 234 1
11=1>1=45>9=16 345 1
11=1>1=45>9=16>2=34 222 1
11=1>1=45>9=16>2=34>7=0 2234 1
11=1>1=45>9=16>2=34>7=0>8=0 22345 1
11=1>1=45>9=16>2=34>7=0>8=0>0=138 22234 1
11=1>1=45>9=16>2=34>7=0>8=0>0=138>5=0 5566 1
11=1>1=45>9=16>2=34>7=0>8=0>0=138>5=0>4=0 664 1
11=1>1=45>9=16>2=34>7=0>8=0>0=138>5=0>4=0>6=10 443 1
11=1>1=45>9=16>2=34>7=0>8=0>0=138>5=0>4=0>6=10>3=11 445 0
11=1>1=47 4453 1
11=1>1=47>9=16 887 1
11=1>1=47>9=16>2=34 67 1
11=1>1=47>9=16>2=340>7=0 98 1
11=1>1=47>9=16>2=34>7=0>8=0 654 1
11=1>1=47>9=16>2=34>7=0>8=0>0=138 5789 1
11=1>1=47>9=16>2=34>7=0>8=0>0=138>5=0 9870 1
11=1>1=47>9=16>2=34>7=0>8=0>0=138>5=0>4=0 3216 1
11=1>1=47>9=16>2=34>7=0>8=0>0=138>5=0>4=0>6=10>3=11 66678 0

my problem is to get the appropriate branch from the above data, which satisfies exactly the values, which i give as the input.
suppose, my input value to search in the above data stack are:

5=0
4=0
6=10
3=11
11=1
1=45
0=138
9=16
2=34
7=0
8=0

for the above given list of key->values, the function should return 11=1>1=45>9=16>2=34>7=0>8=0>0=138>5=0>4=0>6=10>3=11 as the match.
likewise, for another input file, in which another set of keys is given:

5=0
4=0
6=10
3=11
11=1
1=45
9=16
2=34
7=0
8=0

the function should return 11=1>1=45>9=16>2=34>7=0>8=0 1 as the match. not the last line; as that would also match all the values given in my input key, but, i want only the exact match.

Also, I want to find out how many nodes were selected in the given array. (separated by >).

What will be the best way to implement this kind of scenario?

  • 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-13T23:18:17+00:00Added an answer on May 13, 2026 at 11:18 pm
    use strict;
    use warnings;
    
    my $tree;
    while (<DATA>) {
        my @data = split /\>/, (/^([^ ]*)/)[0];
        my $ptr = \$tree;
        for my $key (@data) {
            $ptr = \$$ptr->{$key};
        }
    }
    
    my @inputs = (
        [qw(5=0 4=0 6=10 3=11 11=1 1=45 0=138 9=16 2=34 7=0 8=0)],
        [qw(5=0 4=0 6=10 3=11 11=1 1=45 9=16 2=34 7=0 8=0)]
    );
    
    sub getKey {
        my ( $lu, $node ) = @_;
        exists $lu->{$_} and return $_ for keys %$node;
    }
    
    for my $input (@inputs) {
        my %lu;
        @lu{@$input} = ();
        my @result;
        my $node = $tree;
        while (%lu) {
            my $key = getKey( \%lu, $node );
            if ($key) {
                $node = $node->{$key};
                push @result, $key;
                delete $lu{$key};
            }
            else {
                last;
            }
        }
        print join( '>', @result ), "\n";
    }
    
    __DATA__
    11=1 123 2
    11=1>1=45 234 1
    11=1>1=45>9=16 345 1
    11=1>1=45>9=16>2=34 222 1
    11=1>1=45>9=16>2=34>7=0 2234 1
    11=1>1=45>9=16>2=34>7=0>8=0 22345 1
    11=1>1=45>9=16>2=34>7=0>8=0>0=138 22234 1
    11=1>1=45>9=16>2=34>7=0>8=0>0=138>5=0 5566 1
    11=1>1=45>9=16>2=34>7=0>8=0>0=138>5=0>4=0 664 1
    11=1>1=45>9=16>2=34>7=0>8=0>0=138>5=0>4=0>6=10 443 1
    11=1>1=45>9=16>2=34>7=0>8=0>0=138>5=0>4=0>6=10>3=11 445 0
    11=1>1=47 4453 1
    11=1>1=47>9=16 887 1
    11=1>1=47>9=16>2=34 67 1
    11=1>1=47>9=16>2=340>7=0 98 1
    11=1>1=47>9=16>2=34>7=0>8=0 654 1
    11=1>1=47>9=16>2=34>7=0>8=0>0=138 5789 1
    11=1>1=47>9=16>2=34>7=0>8=0>0=138>5=0 9870 1
    11=1>1=47>9=16>2=34>7=0>8=0>0=138>5=0>4=0 3216 1
    11=1>1=47>9=16>2=34>7=0>8=0>0=138>5=0>4=0>6=10>3=11 66678 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem while dealing with a data set which the value range
Is there any tricky way to implement a set data structure (a collection of
Is there any way to set Inbound Endpoint attributes based on data in an
Is there a python library for encoding ascii data to 7-bit GSM character set
I have a set of data on which I need to perform a topological
I'm iterating through a set of json data which carries results of a few
I am working with some US govt data which has a lengthy list of
I have a set of data points (which I can thin out) that I
Let's say I have a large set of data within which each datum has
I have a data set which has a list of user agents and devices

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.