Perl-Sensitive Sunglasses PerlMonks

### Re^2: comparing and removing values from an array of hashes

by perl_walker (Novice)
 on Oct 22, 2012 at 14:26 UTC ( #1000353=note: print w/replies, xml ) Need Help??

Hi rizzler,

```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

Thanks :) this does almost everthing I needed. Even with my poor skills I can probably work out the rest.

Cheers,

Rizz

Create A New User
Node Status?
node history
Node Type: note [id://1000353]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-04-26 02:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My travels bear the most uncanny semblance to ...

Results (94 votes). Check out past polls.

Notices?