On Jul 29, 2004, at 10:42 AM, perl.org wrote:

Thanks for the detailed response.

Anytime.

It's  easier to read that code bottom to top, so let's start with:

map { m/\.([^.]+)$/ ? [$_, $1] : [$_, ''] } @input;

Unfortunately I really don't find this easy to read.

That's unfortunate, because I actually changed it to that because I hoped it would be easier to follow. I originally used:


map { [ m/^(.+?(?:\.([^.]*))?)$/ ] } @input;

when I was testing your problem, so I'll post that here just to show another approach. (You must use my lc()ed sort with this. The reason I had it that way.)

This solution is more my style, but I worried a bit trickier. It avoids the if/else shorthand of ?:, but you need to at least understand that a regex evaluated in list context returns the list of all the items captured by it's execution to read it.

TIMTOWTDI, as they say. One of the things I prefer about Perl is how it usually leaves me with the choice to approach problems in a way I like.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to