develooper Front page | | Postings from January 2007

Re: simple golf for fun

Thread Previous | Thread Next
Daniel Tiefnig
January 17, 2007 04:42
Re: simple golf for fun
Message ID:
Ton Hospel wrote:
> -p0 s/\G(.*)(.* )(?=\1.\2|$)//g
> This should be about as efficient as a simple regex approach gets.
> It's also the shortest yet :-) It outputs starting from the first
> line that can't be extended. No output means all lines work.

If you're free to output whatever you want on mismatch, you can also
just omit the "\G".

-p0 s/\G(.*)(.*

Will print all lines that preceed invalid changes. (As requested!) One
can create files that will make some problems, though. If a line does
not add at least one character, strange things may happen. But I think
it will always output something.
And until someone proves the contrary, I consider this being the
shortest solution so far. :o)


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About