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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:50:32+00:00 2026-05-16T21:50:32+00:00

I have an array of this kind @uniqarr = qw(error 0 goodrecordno:6123, error 0

  • 0

I have an array of this kind

@uniqarr = qw(error 0 goodrecordno:6123, error 0 goodrecordno:6143, error 1 goodrecordno:10245, error 1 goodrecordno:10678, error 1 goodrecordno:10698, error 2 goodrecordno:16245, error 2 goodrecordno:16123);

I want the o/p as

error 0 goodrecordno:6123
error 1 goodrecordno:10245 
error 2 goodrecordno:16123

i.e each error onetime with its corresponding lowest recordno.
Can anyone help me without using cpan modules

Thanks in advance.

  • 1 1 Answer
  • 1 View
  • 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-16T21:50:32+00:00Added an answer on May 16, 2026 at 9:50 pm

    This is the basic minimum-maximum problem that you’ll find in beginning Perl books. You make one pass through all the elements and remember which one was the lowest as you go along. This is much better than sorting, which is designed for you to put all the elements in order, which is not what you are after.

    use strict;
    use warnings;
    
    # I'll assume those commas were a mistake. You don't need to separate
    # items with commas in a quotewords list
    # If I'm wrong, the process is the same although the data massaging
    # will be a little different
    my @elements = qw(
        error 0 goodrecordno:6123
        error 0 goodrecordno:6143
        error 1 goodrecordno:10245 
        error 1 goodrecordno:10678 
        error 1 goodrecordno:10698 
        error 2 goodrecordno:16245 
        error 2 goodrecordno:16123
        );
    
    my %lowest;
    while( my( $error, $number, $goodrecno ) = splice @elements, 0, 3, () )
        {
        my( $recno ) = $goodrecno =~ /(\d+)/;
    
        # This hash remembers the lowest $recno. If you find another
        # a lower number, you replace the previous value.
        $lowest{$number} = $recno if( 
            ! exists $lowest{$number} 
                ||
            $recno < $lowest{$number}
            );
        }
    

    Once you’ve created the hash that has the lowest elements, you just print it:

    foreach my $number ( sort { $a <=> $b } keys %lowest ) {
        print "error $number goodrecordno:$lowest{$number}\n";
        };
    

    This give you the output that you were looking for:

    error 0 goodrecordno:6123
    error 1 goodrecordno:10245
    error 2 goodrecordno:16123
    

    This is a basic template for these sorts of problems. Step 1: scan the data to remember what you want, using a hash to key those data. Step 2: output the contents of the hash.

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

Sidebar

Related Questions

I have a Deque that contains this kind of stucts. struct New_Array { array<array<int,4>,4>
I have an Array with this kind of values: val = [ ['L-2-4-1','john','bla1'], ['L-1-1-26','bohn','bla2'],
I have this kind of array: $a = array( 'one' => 'one', '0' =>
I have this kind of an array array(5) { [0]=> array(5) { [0]=> string(7)
hi i have this kind of array int[] arrayint = new int[32]; and it
I have this kind of array Array ( [0] => Array ( [id] =>
I have this kind of an array containing single-element arrays: $array = [[88868], [88867],
Ok I have this kind of associative array in PHP $arr = array( fruit_aac
Let's say I have this kind of arrays : <?php $monsterOne['statistics'] = array('attack' =>
guys i have arrays in which i have to match this kind of text

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.