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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:34:19+00:00 2026-06-07T01:34:19+00:00

I want to see if I have repeated items in my array, there are

  • 0

I want to see if I have repeated items in my array, there are over 16.000 so will automate it
There may be other ways but I started with this and, well, would like to finish it unless there is a straightforward command. What I am doing is shifting and pushing from one array into another and this way, check the destination array to see if it is “in array” (like there is such a command in PHP).

So, I got this sub routine and it works with literals, but it doesn’t with variables. It is because of the ‘eq’ or whatever I should need. The ‘sourcefile’ will contain one or more of the words of the destination array.

// Here I just fetch my file


    $listamails = <STDIN>;
    # Remove the newlines filename
    chomp $listamails;
    # open the file, or exit
    unless ( open(MAILS, $listamails) ) {

    print "Cannot open file \"$listamails\"\n\n";
    exit;
    }
    # Read the list of mails from the file, and store it
    # into the array variable @sourcefile
    @sourcefile = <MAILS>;
    # Close the handle - we've read all the data into @sourcefile now.
    close MAILS;


    my @destination = ('hi', 'bye');

    sub in_array
    {
       my ($destination,$search_for) = @_;
       return grep {$search_for eq $_} @$destination;
    }

    for($i = 0; $i <=100; $i ++)

    {
      $elemento = shift @sourcefile;
      if(in_array(\@destination, $elemento))
      {
        print  "it is";
      }
      else
      {
        print "it aint there";
      }
    }

Well, if instead of including the $elemento in there I put a ‘hi’ it does work and also I have printed the value of $elemento which is also ‘hi’, but when I put the variable, it does not work, and that is because of the ‘eq’, but I don’t know what else to put. If I put == it complains that ‘hi’ is not a numeric value.

  • 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-07T01:34:22+00:00Added an answer on June 7, 2026 at 1:34 am

    By the way, when looking for duplicates in a large number of items, it’s much faster to use a strategy based on sorting. After sorting the items, all duplicates will be right next to each other, so to tell if something is a duplicate, all you have to do is compare it with the previous one:

    @sorted = sort @sourcefile;
    for (my $i = 1; $i < @sorted; ++$i) {   # Start at 1 because we'll check the previous one
        print "$sorted[$i] is a duplicate!\n" if $sorted[$i] eq $sorted[$i - 1];
    }
    

    This will print multiple dupe messages if there are multiple dupes, but you can clean it up.

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

Sidebar

Related Questions

I have a LinearLayout and I want to see when a user has touched
I have a list of keywords and want to see if one cell contains
I have a executable jar file and i want to see code behind it.
I have the exact string : 123.. I want to see what its length
I have program that runs fast enough. I want to see the number of
I have some elements and I'm using some jQuery plugins. I want to see
I have sixteen servers using Log4J logs, accessible by ssh. I want to see
I have a dynamic site with MySQL database and I want to create see
I have a .mat file that I want to open and see its contents.
I have a dataset and I want to test to see how close it

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.