alwaysonnet <> wrote:
> I've got an array of hash-references as following.
If you say so, but those are some mighty cumbersome keys...
> ( i've represented
> hash-references as a table below)
Why have you done that rather than representing them in real Perl
code that an answerer could use to test any potential answers?
If you make the answerer do that extra work, they are likely to move on
to helping some other poster who has taken the time to make it
easier for them to give an accurate answer.
Have you seen the Posting Guidelines that are posted here frequently?
[ snip the table ]
> I want to display all the active accounts (status with "Y") before
> inactive accounts along with preserving the order by type ie., Prefund
^^^^^^^^^^^^^^^^^^^^
> should come first before Receipt and Payment along the order.
Recent perls have a "stable" sort, so you should get that by default.
> if ($label->{'batype'} eq "Payment") {
^^^^^^
That is not the key that you said in the table. Which is it?
Precision is important in programming...
> Is there any way of how to achieve this by sorting according to status
> by preserving the account type order.
Yes, and it is a plain old everyday sort that you should have been
able to get simply by reading the docs about sorting...
----------------------------
#!/usr/bin/perl
use warnings;
use strict;
use Data:

umper;
my @records = (
{ 'Type' => 'Prefund', 'A/C No' => 12345, 'Status(active/inactive)' => 'Y' },
{ 'Type' => 'Prefund', 'A/C No' => 45678, 'Status(active/inactive)' => 'N' },
{ 'Type' => 'Receipt', 'A/C No' => 78878, 'Status(active/inactive)' => 'N' },
{ 'Type' => 'Receipt', 'A/C No' => 32365, 'Status(active/inactive)' => 'Y' },
{ 'Type' => 'Payment', 'A/C No' => 56546, 'Status(active/inactive)' => 'N' },
{ 'Type' => 'Payment', 'A/C No' => 23456, 'Status(active/inactive)' => 'N' },
{ 'Type' => 'Payment', 'A/C No' => 34093, 'Status(active/inactive)' => 'Y' },
);
my @sorted = sort { $b->{'Status(active/inactive)'} cmp
$a->{'Status(active/inactive)'}
} @records;
print Dumper \@sorted;
----------------------------
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas