Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Finding first block of contiguous elements in an array

by Arien (Pilgrim)
on Dec 21, 2002 at 16:29 UTC ( #221640=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://221640]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2020-05-27 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (152 votes). Check out past polls.

    Notices?