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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:21:36+00:00 2026-06-05T02:21:36+00:00

I am looking for some help in one senario. Requirement: Through some validation, I

  • 0

I am looking for some help in one senario.

Requirement:

Through some validation, I have strored following kinds of value in one array.

@array_name = ("Rajesh","Raju","Ram","John","peter");

Now I know from some background that “Rajesh”, “Ram”, “peter”, are duplicate entries so I would expect my output to be:

@array_name = ("Rajesh","Raju","John");
# or 
@array_name = ("Ram","Raju","John");
# or 
@array_name = ("peter","Raju","John");

I have done example program such as below but it does not satisfy me…

    my $spcific_output ="";
    my $output ="";

    foreach my $name (@array_name) 
    {
        if($name eq "Rajesh" || $name eq "Ram" || $name eq "peter")
        {
            $spcific_output = "Rajesh and Ram and peter");
        }
        else
        {
            $output .= "My Name is $name";
        }
    } 
    $output .= $spcific_output;

Any best way to achieve 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-05T02:21:37+00:00Added an answer on June 5, 2026 at 2:21 am

    If you’re using v5.10 or higher you can use smart matching on an array with your duplicate names:

    #!/usr/bin/env perl
    use strict;
    use warnings;
    use Data::Dumper;
    
    my @names = qw(Rajesh Raju Ram John Peter);
    my @dupl = qw(Rajesh Ram Peter);
    my $seen;
    
    my @names = grep {$_ ~~ @dupl ? !$seen++ : 1} @names;
    
    print Dumper \@names;
    

    Output:

    $VAR1 = [
              'Rajesh',
              'Raju',
              'John'
            ];
    

    The condition in grep evaluates !$seen++ if a name from @names is in @dupl, and keeps $_ only when $seen is 0. Otherwise 1 (true) is evaluated and $_ is kept.

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

Sidebar

Related Questions

i've run out of idea's on this one so looking for some help to
I'm looking for an online introduction to occam 2. Could some one help me?
looking for some help with images referenced within the stylesheet. I have no problems
I have posted this a few times looking for some help, I cant seem
-Hello, looking for some help. We currently have a winform app used to do
I need some help. I'm looking to have a sidebar that toggles when a
I am looking for some help with a MYSQL query. I have two tables,
I'm looking for some help/suggestions for backing up two large databases to one server
I am looking for some help with XSLT to transform one xml file into
Looking for some help! I need to split a string at the last occurrence

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.