http://www.perlmonks.org?node_id=1000346

rizzler has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, I have an issue that needs to be solved as part of my perl code and I feel i am in over my head. Any help would be greatly appreciated. I have an array of hashes and I need to compare the values in these arrays and based on several criteria only keep 1 of the arrays.

Here is an example of whats in my array:

#/usr/bin/perl use warnings; use strict; use Data::Dumper; my $a="A,Star_1GB,MONTH,1000,0"; my $b="B,Unlim60,MONTH,1000,6000"; my $c="C,Unlim,DAY,50,6000"; my $d="D,,MONTH,500,8000"; my @DA_head=qw(name check duration quantity price); my @DA; foreach ($a,$b,$c,$d){ my %rec; @rec{@DA_head} =split(',',$_); push @DA, \%rec; } print Dumper(\@DA);

I need to compare the values in the array, maybe sort them on the following criteria, Here is my criteria:

1. Is there a value in check.

2. what value has the longest duration, this is in field duration and I need to keep MONTH over WEEK over DAY.

3. Which has the highest value in quantity.

4. which has the highest price.

I need then remove all the values to just be left with the array that best matches the criteria.In this case I should only be left with B.

Thanks in Advance.

Rizz.