in reply to Regex style and efficiency
Because it is simple and efficient:
$s = 'variable chars anchor want this';; $s = substr $s, index $s,'anchor';; print $s;; anchor want this
If I was going to use a regex (say the anchor had a variable component), then:
$s = 'variable chars anchor want this';; $s =~ s[.+(?=anchor)][];; print $s;; anchor want this
The difference:
cmpthese -1,{ a=> q[$s='variable chars anchor want this';$s=~s[.+(?=anchor)][];] +, b=> q[$s='variable chars anchor want this';$s=substr $s, index $s, +'anchor';] };; Rate a b a 1592446/s -- -48% b 3055291/s 92% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex style and efficiency
by bobf (Monsignor) on Jan 10, 2010 at 22:23 UTC | |
|
Re^2: Regex style and efficiency
by ikegami (Patriarch) on Jan 11, 2010 at 01:04 UTC |