--- Nic LAWRENCE <[EMAIL PROTECTED]> wrote:
> Can anybody suggest the most efficient method to do the following...
>
> I have an array of email aliases like the following:
> [EMAIL PROTECTED]: sys
> [EMAIL PROTECTED]: coookiecom
> [EMAIL PROTECTED]: niccicamcom
> [EMAIL PROTECTED]: katyland-news_site14-request
> [EMAIL PROTECTED]: majordomo_site4
> [EMAIL PROTECTED]: melanier
> [EMAIL PROTECTED]: louisefolds
> [EMAIL PROTECTED]: swccom
>
> ... and I want to sort them in alpha order, but basic on the value
> between @ and : (ie the domain name in the first column). I could
> problably do this if I throught about it a while, but the code would
> be REALLY messy, so I'm interested to know what the "correct" way to
> go about it might be. :)
lol... Assuming they are in @ary, try this:
@new = sort {
my($A) = $a =~ /\@([^:]+)/;
my($B) = $b =~ /\@([^:]+)/;
return $A cmp $B;
} @ary;
sort aliases each element to $a and $b when comparing; the pattern
grabs all consecutive non-colons following the first at sign.
Assignment in the list context prvided by the parens around $A and $B
means that the actual pattern matched is returned. cmp does a string
compare, returning the greater-equal-lessThan zero comparison sort
expects. =o)
=====
print "Just another Perl Hacker\n"; # edited for readability =o)
=============================================================
Real friends are those whom, when you inconvenience them, are bothered less by it than
you are. -- me. =o)
=============================================================
"There are trivial truths and there are great Truths.
The opposite of a trival truth is obviously false.
The opposite of a great Truth is also true." -- Neils Bohr
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/