in reply to Re: comparing and removing values from an array of hashes
in thread comparing and removing values from an array of hashes
Hi rizzler,
I think this may help you,
my %quantity=(YEAR => 5, MONTH => 4, WEEK => 3, DAY => 2, HOUR =>1); my $a1="A,Star_1GB,MONTH,1000,0"; my $b1="B,Unlim60,MONTH,1000,6000"; my $b2="B,Unlim60,YEAR,1000,6000"; my $c1="C,Unlim,DAY,50,6000"; my $c2="C,Unlim,HOUR,50,6000"; my $d1="D,,MONTH,500,8000"; my @vals = ($a1, $b1, $b2, $c1, $c2, $d1); @vals = map{$_->[0]} sort{$quantity{$b->[1]} <=> $quantity{$a->[1]}} s +ort{$b->[2] <=> $a->[2]} sort{$b->[3] <=> $a->[3]} map{[$_, /(YEAR|MO +NTH|WEEK|DAY|HOUR),([^,]*),([^,]*)$/i]} @vals; print join("\n",@vals);
Output will be:
B,Unlim60,YEAR,1000,6000 B,Unlim60,MONTH,1000,6000 A,Star_1GB,MONTH,1000,0 D,,MONTH,500,8000 C,Unlim,DAY,50,6000 C,Unlim,HOUR,50,6000
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: comparing and removing values from an array of hashes
by rizzler (Novice) on Oct 22, 2012 at 17:10 UTC |
In Section
Seekers of Perl Wisdom