in reply to Re: How can I sort my array numerically on part of the string? (updated)
in thread How can I sort my array numerically on part of the string?
>
sort { ($a=~/(\d+),/)[0] <=> ($b=~/(\d+),/)[0]
You need that (...)[0] for the match to return the captures in list context, ( <=> is enforcing scalar context and m// only returns captures in list context otherwise boolean )
I'm wondering if there is a prettier solution for that.
The Schwartzian transform doesn't have that limitation.
... map { [$_, /(\d+),/] } @list;
should do already.
update
clarification: any better solution than (...)[0] to get list context ?
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In Section
Seekers of Perl Wisdom