Here's a capture in list context. Prettier?
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11124461 use warnings; my @list = ( '1,cat', '2,dog', '22,mouse', '11,eel', '001,elk', '13,mi +nk'); my @n; @n[ /(\d+),/ ] .= "$_\n" for @list; print grep defined, @n;
This is why perl is fun :)
|Replies are listed 'Best First'.|
Re^4: How can I sort my array numerically on part of the string? (updated)
by LanX (Cardinal) on Dec 02, 2020 at 11:06 UTC
by misterperl (Scribe) on Dec 02, 2020 at 13:44 UTC