Like others, I immediately reach for (split)[n] in a situation like this, so I thought I'd benchmark that against the other ideas offered in this thread. split was more than twice as fast as a regex, which wasn't a surprise, but johngg's combination of substr and rindex stomped it. The first run below used the sample string given by the OP, and then I ran it again using a string 32 times as long (with 32 times the delimiters). The substr/rindex solution only gets better with length. Have to remember that one!
# with a short string regex it 520833/s -- -56% -88% split it 1176471/s 126% -- -73% index it 4347826/s 735% 270% -- # with a long string Rate regex it split it index it regex it 20053/s -- -68% -100% split it 62004/s 209% -- -99% index it 4784689/s 23761% 7617% --
Aaron B.
Available for small or large Perl jobs; see my home node.
In reply to Re: Simple way to split on last match?
by aaron_baugher
in thread Simple way to split on last match?
by aturtle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |