develooper Front page | perl.fwp | Postings from December 2001

Re: The Santa Claus Golf Apocalypse

Thread Previous | Thread Next
From:
Piers Cawley
Date:
December 6, 2001 15:56
Subject:
Re: The Santa Claus Golf Apocalypse
Message ID:
m24rn36hik.fsf@bofh.org.uk
Michael G Schwern <schwern@pobox.com> writes:

> On Fri, Dec 07, 2001 at 10:01:05AM +1100, Andrew.Savige@ir.com 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?

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About