Front page | perl.fwp |
Postings from March 2002
Re: TPR1 post-mortem
Thread Previous
|
Thread Next
From:
Stephen Turner
Date:
March 9, 2002 09:00
Subject:
Re: TPR1 post-mortem
Message ID:
Pine.LNX.3.96.1020309165126.19505D-100000@gentoo
Some Perl features I noticed while playing this game. Maybe someone would
be kind enough to explain them.
1) s/\B./$&$&/g doesn't work -- we've discussed that.
2) This works:
sub _{local$a;print$_=pop,$/;/..(?{$a.=$&%9||9*!!-$&})\b/&&_($a)}_ pop
But with "my" instead of "local" it doesn't. I don't understand this. (I was
trying to shorten $a='').
3) Why is -"00" equal to "-0"? This cost me a stroke. It doesn't seem to
satisfy the rules for numeric minus (which should just give "0") or string
minus (which should give "-00").
4) I had to waste a character by using /..(?{CODE})\b/ instead of
/..(?{CODE}$/. Actually, I do understand this. The regex optimiser is too
smart, and only looks at the end of the string when it sees the $, but
thankfully it's not smart enough only to look near word boundaries even when
there's a \b in there.
I could make a case for turning off the optimiser in the presence of
(?{CODE}) subpatterns, and behaving exactly like "The Little Engine That
/Could(n't)?/". Or at least the optimiser should be turn-offable. Otherwise
you have to understand what optimisations the optimiser is going to make
before you can predict the behaviour of the (?{CODE}).
--
Stephen Turner, Cambridge, UK http://homepage.ntlworld.com/adelie/stephen/
"This is Henman's 8th Wimbledon, and he's only lost 7 matches." BBC, 2/Jul/01
Thread Previous
|
Thread Next