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

Re: [MacPerl] sorting arrays



At 16:26 1999-06-17 -0400, Richard Gordon wrote:
> 
>...
>I understand that it has potential benefit under some circumstances, but it >struck me as unduly awkward to bother with in the context of the original >question, e.g., how do I sort & print these names? If that's all you want to >do, what's wrong with:
>
> @fields = <INFILE>;
> s/\|\|/, /g;
> print sort @fields;


It doesn't work, that's what's wrong with it.

Unless my understanding of Perl is completely wrong (and let's not
exclude the possibility :-) the second line is operating on the
value of $_. I don't believe that's even set in this example; it
certainly isn't going to loop over an entire array all by itself.

Even if the attempted substitution worked, swapping "||" for ","
doesn't affect the sorting. I think it is clear that the names
should be sorted alphabetically by first one name and then the
other, *not* by alphabetical order of concatenating them.

For instance, to borrow Bart's example,

	Jansens||Fientje
	Jansen||Erik

still comes out wrong even if you use commas:

	Jansens, Fientje
	Jansen, Erik

because comma, like pipe, sorts after "s".

Peter.


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