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.
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.
Once you’ve created the hash that has the lowest elements, you just print it:
This give you the output that you were looking for:
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.