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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:09:48+00:00 2026-06-05T19:09:48+00:00

I have two arrays, @names and @employees , that are filled with strings that

  • 0

I have two arrays, @names and @employees, that are filled with strings that represent names. @names is 2 dimentional, holding references to anonymous arrays, but the location of the data we care about is at @names[i][0]. I want to loop through @names and find which names are not in @employees.

At first I thought that looping through @names backwards, comparing it to @employees and deleting any matches from @names would work, but I run into some errors. Here’s what I have:

for my $i (reverse(0 .. $#names)) {
  foreach my $employee (@employees) {
    if ($names[$i][0] eq $employee) {  # line 67
      splice(@names, $i, 1);
    }
  }
}

I run into this error:

Use of uninitialized value in string eq at script.pl line 67, line 2.

The strings are all defined in the array. So I’m guessing that this is caused from me deleting elements in the array while I am looping through it, but I thought that looping through the array backwards would prevent an issue like this from happening.

So where am I going wrong in my loop? Also, I’ve been really struggling with this loop and that hints to me that something is wrong with my entire thought process. Is there a better method to do this?

  • 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-05T19:09:50+00:00Added an answer on June 5, 2026 at 7:09 pm

    There’s no reason to explicitly loop here. You want to filter names: that’s a grep. You want to check membership: that could be done by a grep too.

    @names = grep {my $name = $$_[0]; not grep $_ eq $name, @employees} @names;
    

    The repeated scanning of the inner array isn’t particularly efficient; it can be avoid by pre-populating a set (really a hash) ahead of time.

    my %employees = map +($_ => 1), @employees;
    @names = grep !$employees{$$_[0]}, @names;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays: var columns = ["Date", "Number", "Size", "Location", "Age"]; var rows
I have two js arrays already, say: names and values (with the same length),
I have two arrays. One is an array of names and the other is
I have two arrays as follows. And I want to pick up names from
I have two arrays of student names and test scores. Each array contains only
I have two arrays 1)nameArray; 2)numberArray; These arrays contains names and numbers , I
I have two arrays one is for names and another is for phone numbers,and
I currently have two arrays one the stores a file name and another that
I have two arrays. In first array I have Type and Zone field names.
So I have two arrays, $gDatabaseKeyNames (list of column names) and $gDatabaseKeyValues (a list

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.