in reply to Foreach Loop in Data Scraping

It could be as simple as this:

while( $string =~ m/(SUMMARY.+?DESCRIPTION)/ig ) { print "Summary: $1\n" }

The while() loop continues looping as long as its condition is true. In this case, the condition is whether or not a match occurs. And by using the /g modifier, multiple matches can be detected within the same string. Each time a match occurs the internal position marker advances so that the next match will come after the current match. perlre and perlretut describe the use of the /g modifier in greater detail.

I removed the leading and trailing instances of .+?, because I don't think they were actually doing anything useful for you, and they potentially get in the way of repeated matches (the /g modifier). As you're probably aware, .+? says to non-greedily match one or more characters. If your only reason for that is to assure that there is at least one character separating matches, you could just do it with a single dot to the left and right of the capture. We're not trying to anchor to anything outside of the capture anyway, from what I can tell.


Dave

Replies are listed 'Best First'.
Re^2: Foreach Loop in Data Scraping
by MiriamH (Novice) on Jun 19, 2012 at 17:51 UTC

    Good point. I guess I was over thinking it. Thank you!

    But your code doesn't cut off after the description, it just breaks the code into lines that each start with the event title. Definitely a step in the right direction!