Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Finding first block of contiguous elements in an array

by hossman (Prior)
on Dec 21, 2002 at 06:05 UTC ( #221578=note: print w/replies, xml ) Need Help??


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

It's not clear if the only thing you want is the first occurence of TITLE, but assuming it is, the simplest thing to do is to just stop processing your input stream once you are done with first set of title lines. And if you want to avoid "flag" vaiables, you can allways use a nested loop over the input handle.

something like this (psuedo-perl) perhaps...

while (<STDIN>) { next unless /^TITLE\s+(.*)$/; my $title = $1; while (<STDIN>) { last unless /^TITLE\s+\d+\s+(.*)$/; $title .= $1 } print "Here is the title you wanted: $title"; last; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2020-05-26 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (150 votes). Check out past polls.

    Notices?