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

Re: [MacPerl] sorting arrays



At 09:21 -0400 6/16/1999, cetasix@pop.erols.com wrote:
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?

I couldn't get this to work either. I thought that maybe using sort inside of the foreach loop was the problem, but that doesn't seem to be it. Maybe Chris or somebody can get to the bottom of this, but the following will work if you just want to sort the list and don't care how ugly it is:

open(INFILE,"names.txt") || die("Cannot open names.txt");
@fields = <INFILE>;
s/\|\|/, /g;
print sort @fields;
close(INFILE);

BTW, when I was in Shuck trying to figure this out, I became curious about a related something- does anyone know what the hell a Schwartzian Transform is?



Richard Gordon
--------------------
Gordon Consulting & Design
Database Design/Scripting Languages
mailto:richard@richardgordon.net
http://www.richardgordon.net
770.565.8267