Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Something like this, you mean?

use strict; use warnings; my $offset = 0; # Where are we in the string? my $string = do { # Grab the string. local $/; <DATA>; }; my $numResults = 0; while (1) { my $idxSummary = index($string, "SUMMARY", $offset); my $result = ""; if ($idxSummary > -1) { $offset = $idxSummary + length("SUMMARY"); my $idxDescription = index($string, "DESCRIPTION", $offset); if ($idxDescription == -1) { print "(Data malformed: missing DESCRIPTION line.)\n"; last; } my $length = $idxDescription - $offset; $result = substr($string, $offset, $length); $offset = $idxDescription + length("DESCRIPTION"); $result =~ s/^\s+|\s+$//g ; # Strip leading and trailing white +space, # includng newlines. $numResults++; } else { print "(All done. $numResults result(s) found.)\n"; last; } print " <$result>\n"; } __DATA__ This is bogus data SUMMARY Event 1 DESCRIPTION Lorem ipsum etc etc This is bogus data SUMMARY Event 2 DESCRIPTION Lorem ipsum This is bogus data SUMMARY The Third Event DESCRIPTION Lorem ipsum This is bogus data SUMMARY Event Number Four DESCRIPTION Lorem ipsum

It gives this output:

<Event 1> <Event 2> <The Third Event> <Event Number Four> (All done. 4 result(s) found.)

Update: Alternatively, if it's not really the indexes you care about, but only capturing those titles, how about this?

my @results = $string =~ m/SUMMARY\s*(.+?)\s*DESCRIPTION/g; print map { " <$_>\n"} @results;

In reply to Re: Automatic Subsequent Indexing. by muba
in thread Automatic Subsequent Indexing. by MiriamH

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found