Don't ask to ask, just ask | |
PerlMonks |
Re^2: How can I sort my array numerically on part of the string? (updated)by LanX (Saint) |
on Dec 02, 2020 at 02:09 UTC ( [id://11124496]=note: print w/replies, xml ) | Need Help?? |
>
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.
updateclarification: any better solution than (...)[0] to get list context ?
Cheers Rolf
In Section
Seekers of Perl Wisdom
|
|