[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] sorting arrays



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

I'm using the following code and it does not seem to sort them.

if(open(INFILE,"names.txt") || die("Cannot open names.txt")) {
	while (<INFILE>) {
		@fields = $_;
		foreach $field (@fields) {
			@array = split /\|\|/, $field;
			@array = sort(@array);
			chomp($array[0],$array[1]);
			$lastname = $array[0];
			$firstname = $array[1];
			print "$lastname, $firstname\n";
		}
	}
	close(INFILE);
}

It does not seem to work. Is there something I'm missing in the code?

Thanks in advance.

alan :)



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org