[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
Re: [MacPerl] sorting arrays
At 09:21 -0400 6/16/99, cetasix@pop.erols.com wrote:
> I am trying to sort a simple text file:
> Janssen||Willem
> Hinders||Trintje
> Beving||John
> Beving||Henrietta
> Beving||Ubbe
> Beving||Henry
> Beving||Henry
> Beving||Etta
> Beving||Minnie
> Beving||Bertha
> Willemssen||male
> Willemssen||male
> Willemssen||Wopka(e)
> Brower||Coba
> Brower||John
> Brower||Bertha
Is it more than just a simple sort you want? That is, do you want to _do
something_ with the data? Or just sort it?
Have I missed something?
script:
#!perl
open(IN, "names.txt") or die "Oops";
@names = <IN>;
# note this is an ASCII (case-sensitive) sort; you may want to
# "improve" on that
@sorted = sort @names;
foreach (@sorted) {
print;
# note you could now split or substitute ", " for the || or...
# What are you trying to accomplish? Beyond a simple sort?
}
results:
Beving||Bertha
Beving||Etta
Beving||Henrietta
Beving||Henry
Beving||Henry
Beving||John
Beving||Minnie
Beving||Ubbe
Brower||Bertha
Brower||Coba
Brower||John
Hinders||Trintje
Janssen||Willem
Willemssen||Wopka(e)
Willemssen||male
Willemssen||male
-- --
|\ _,,,---,,_ Vicki Brown <vlb@cfcl.com>
ZZZzz /,`.-'`' -. ;-;;,_ Journeyman Sourceror: Scripts & Philtres
|,4- ) )-,_. ,\ ( `'-' P.O. Box 1269 San Bruno CA 94066
'---''(_/--' `-'\_) http://www.cfcl.com/~vlb http://www.macperl.org
===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org