First, you need an "else { () }" so that you return an empty list when you don't match (right now you are returning a scalar false value instead, which is roughly an empty string). And $a being "" means that $a->[0] is accessing the array that has an empty name (which means either you aren't useing strict or you have no unmatching lines).
If that change alone doesn't speed things up enough, then you can certainly do sorting faster than a Schwartzian Transform (creating all of those tiny anonymous arrays does require a bit of time and memory), though the ST is less prone to some common coding errors.
- tye (but my friends call me "Tye")my @sorton; my @lines= grep { if( m/^(.+?)\((\d+)\)\s-\s\[(.+?)\].+?"(.*?)"\.$/ ) { push @sorton, $1.pack("N",$2).$3; 1; } } <DATA>; my @idx= sort { $sorton[$a] cmp $sorton[$b] } 0..$#sorton; foreach( @lines[@idx] ) { print $_; }
In reply to (tye)Re: Complex Sorting Optimization?
by tye
in thread Complex Sorting Optimization?
by orbital
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |