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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:53:13+00:00 2026-06-10T01:53:13+00:00

I want to get the corresponding values from the second list based on the

  • 0

I want to get the corresponding values from the second list based on the index value of the unique values in my first list using perl.

For ex:

@list1=('a','b','c','a','d');
@list2=('e','f','g','a','i');

i want to create two new list without the duplicate values

@new_list1=('a','b','c','d');
@new_list2=('e','f','g','i');

How can i do this?

to get unique values from one list i can use:

my %temp_hash = map { $_, 0 } @list1;
my @uniq_array = keys %temp_hash;   
print "@uniq_array\n";

But how to get the values at the corresponding index from the other list.

Thanks in advance.

EDIT:
It should find unique values based on some condition and not the first occurrence.
for ex:

@list1=('a','b','c','a','d');
@list2=('e','f','g','a','i');

and

@list1=('a','b','c','a','d');
@list2=('a','f','g','e','i');

should give the same value:

@new_list1=('a','b','c','d');
@new_list2=('e','f','g','i');

In the given example the condition may be not to include the common element where the value for both the list are same. ie there are two occurrence of ‘a’ 1st ‘a’ corresponds to ‘e’ and 2nd ‘a’ corresponds to ‘a’. so the second one is to be removed not the first one.

  • 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-10T01:53:15+00:00Added an answer on June 10, 2026 at 1:53 am

    When dealing with parallel arrays, one deals with indexes. To find the list of indexes, one can start with the following common method of finding unique values:

    my %seen;
    my @uniq = grep !$seen{$_}++, @dups;
    

    and expand it to take a list of indexes as input:

    my %seen;
    my @indexes = grep !$seen{ $list1[$_] }++, 0..$#list1;
    

    In your updated question, you need something more complex:

    my %options;
    for (0..$#list1) {
       push @{ $options{ $list1[$_] } }, $_;
    }
    
    my %seen;
    my @indexes;
    for (0..$#list1) {
       next if $seen{$_}++;
       my @options = @{ $options{ $list1[$_] } };
       my $option = pick(\@list1, \@list2, \@options) // $options[0];
       push @indexes, $option;
    }
    

    Then all you have to do is extract the desired elements:

    my @new_list1 = @list1[ @indexes ];
    my @new_list2 = @list2[ @indexes ];
    

    The pick function for the possible selection algorithm you describe is:

    sub pick {
       my ($list1, $list2, $options) = @_;
       return ( grep $list1->[$_] ne $list2->[$_], @options )[0];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get specific value based on request from the property file.how to
I am trying to get all values (except corresponding to a particular key) from
I want to get values from other sheets. I have some values in Excel
I want to get two field values from a database table and combine them
I have a list view that displays values (names) I get from my website,
I want to store a user setting(language). so i can get the corresponding resources
I want get as much as possible from Redis + Hiredis + libevent. I'm
What I want: get a xml from the AppData to use What I code
Basically I want get data I already have accessed from javascript and passing it
I just want get a 2 dimension array of List in c#. In my

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.