Interesting problem. Maybe you could do something with a hash for your keys? This doesn't completely match your spec, although it matches your example. Perhaps you can adapt this for your needs...
my %keys = (
a=>1,
e=>2,
i=>3,
o=>4,
u=>5,
);
my @records = ();
push @records, '1|2|3|d|4';
push @records, '1|2|3|a|4';
push @records, '1|2|3|d|4';
push @records, '1|2|3|o|4';
my @final = ();
my @result = ();
my $re = '';
map {my @flds=split /\|/; push @{$final[$keys{$flds[3]}||0]},$_} @reco
+rds;
# note that entry 0 is where the unmatched elements wind up...
print map{ "@{ $final[$_] }\n" } grep defined $final[$_],1..$#final;
Maps used only for their side effects are kinda wierd, though. I'd replace the map with a foreach(@records) block so it's clearer what you're doing.
foreach(@records)
{
my @flds=split /\|/;
push @{$final[$keys{$flds[3]}||0]},$_;
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.