in reply to How do I alphabetize a list of email addresses by domain?

Wield the Schwartzian Transform for the powers of good:

@sortedEmails = map {$_->[0]} sort {$a->[2] cmp $b->[2]} map {[$_, split /@/]} @emails;

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Replies are listed 'Best First'.
Re: Re: How do I alphabetize a list of email addresses by domain?
by Kanji (Parson) on Apr 20, 2002 at 07:56 UTC

    That only sorts @emails by domains. To further sort the addresses within each domain, you'd need something like ...

    sort { $a->[2] cmp $b->[2] # by domain first, || $a->[1] cmp $b->[1] # then username }

    Update: Oops, missed the ||. Thanks Chmrr.

        --k.


      That only sorts @emails by domains.

      Quite admittedly. But to quote the original poster:

      How do I alphabetize a list of email addresses by domain?

      ..but I can quite see your point. Anyways, you'll want to plonk an "or" between your two lines of code so that it compiles. :)

      Depending on how much the anonymous monk cares, they may or may not want to go whole hog and use Zaxo's more precise and tolerant answer.

      perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'