Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Search all occurences of text delimited by START and END in a string

by flexvault (Monsignor)
on May 12, 2015 at 13:29 UTC ( [id://1126425]=note: print w/replies, xml ) Need Help??


in reply to Search all occurences of text delimited by START and END in a string

Hello natol44,

Have you looked at the 3rd optional parameter of 'index'. 'index' is very fast and since you have a large string, you can loop until the end by starting the next search('index') with the end of the most recent end of your search. (untested code):

my $pos = 0; while ( $pos < length( $all ) ) { my $si = index ( $all, "<START>", $pos ); if ( $si < 0 ) { last; } my $sj = index ( $all, "<END>", $si+1 ); if ( $sj > $si+1 ) { ... Collect you string with 'substr' etc. } $pos = $sj + 4; # set search for finding next text. }
Note: There are working examples in the Perl Cookbook and also using Super Search.

Regards...Ed

"Well done is better than well said." - Benjamin Franklin

  • Comment on Re: Search all occurences of text delimited by START and END in a string
  • Download Code

Replies are listed 'Best First'.
Re^2: Search all occurences of text delimited by START and END in a string
by natol44 (Sexton) on May 17, 2015 at 17:16 UTC
    Thank you all, and especially Ed, whose method was the best for me!

Log In?
Username:
Password:

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

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

    No recent polls found