in reply to Re: Re: Split Function - Positions
in thread Split Function - Positions

Agreed. Though I had thought that by grabbing the matches using a standard m[([^X]+)]g first, I would know how big to make the big re. Then a second pass would populate @-.

As it turn out,

push @posns, pos($screen) - length $1 while $screen =~ /([^X]+)/g;

is substantially faster than

push @posns, $-[ 0 ] while $screen =~ m[([^X]+)]g;

which surprised me. I'm not sure why that would be?

My best guess is that @- uses tie-style magic, and isn't populated unless it is accessed rather than when the regex runs? Perhaps the captures are made in the form of LVALUE refs and @- and @+ are derived from those if and when they are called for?


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail