I don't know if this is "correct" but I would use sort and pass in a custom
compare function.

@sortedArray = sort { compareDomains() } @unsortedArray;

sub compareDomains {
        my ($userA, $domainA) = split /@/, $a;
        my ($userB, $domainB) = split /@/, $a;

        return ($domainA cmp $domainB);
}

I guess if you don't care at all about the user portion you could use s///
to chop off everything upto and including the @.

"Just 2 bits"
Peter C.

-----Original Message-----
From: Nic LAWRENCE [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 10, 2001 2:23 PM
To: 'Beginner Perl'
Subject: Sorting


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. :)

Any ideas?

Reply via email to