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.


In reply to comparing and removing values from an array of hashes by rizzler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.