Michael G Schwern <[EMAIL PROTECTED]> writes:
> On Fri, Dec 07, 2001 at 10:01:05AM +1100, [EMAIL PROTECTED] wrote:
>> --- mid.pl ---------------------------------------------
>> #!/usr/bin/perl -p0
>> $_=$1while/.^(.+)^/ms
>
> Someone want to explain why this works?
Is it not obvious? In an 'ms' context, '.' matches *everything*
newlines included, and ^ can also match just after a newline.
So, given a string:
1\n2\n3\n4\n5\n
you get
2\n3\n4\n
Then
3\n
And then you stop.
Definitely one of those 'a ha' moments when I found this one, 'cos I'd
been using
@a=<>;print@a[$#a/2..@a/2]
up 'til then. Quite hard to see past it as well.
--
Piers
"It is a truth universally acknowledged that a language in
possession of a rich syntax must be in need of a rewrite."
-- Jane Austen?