Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Finding first block of contiguous elements in an array

by hossman (Prior)
on Dec 21, 2002 at 06:05 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://221578]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-19 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found