in reply to Finding first block of contiguous elements in an array

Can anyone think of an elegant way to grab the first block of 1+ contiguous TITLE lines, and stop?
my $title; for (@data) { if (/^TITLE\s+\d*(.*)/) { $title .= $1; } else { last if defined $title; } }

The elegance would be in not adding a flag but rather reusing $title for that purpose (since it already contains the state the flag would save).

— Arien

Replies are listed 'Best First'.
Re: Re: Finding first block of contiguous elements in an array
by BrowserUk (Pope) on Dec 21, 2002 at 16:36 UTC

    'cept that that will bottle out too early unless the first line is a title line (which it isn't)?

    Update: Talking That which begins with B and ends in ollocks again. Arien++


    Examine what is said, not who speaks.