Re: using Perl's index function
On Tue, 3 Aug 2004 12:05:10 -0700, you wrote: >The logic I am using may be summarized like so: > >if( >($textarea_line =~ m/^\s*(Exhibit\s+[\d.]+(\s*\([0-9a-zA-Z]+\))*)\s*$/i) || >($textarea_line =~ m/^\s*(FORM\s+10\-K)\s*$/i) || >($textarea_line =~ m/^\s*(FORM\s+10\-K[A-Z]*\/*[A-Z]*)$/i) || >($textarea_line =~ m/^\s*(FORM\s+8\-K)\s*$/i) ) > >I was using the index function to get the position of the particular >heading that triggered the match: > > $heading = $1; > $heading_offset = index($textarea, $heading); > >Being the rocket scientist I am, it took me all morning to figure out >why I was getting inaccurate results. Then I finally went back to the >manual and re-discovered that index returns the position of the FIRST >occurrence of substring within string. > >First occurrence doesn't help me. I need, naturally, the exact >occurrence (whether the fifth or the hundredth) that triggered the match. The @+ and @- arrays should do the job. See perldoc perlvar. -- Eric Amick Columbia, MD ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
using Perl's index function
I'm searching a textarea that has been split into an array of lines. I'm looking for certain keywords that are centered like headings, or all by themselves on a line, right or left justified. They may also be scattered in the text within sentences, but I don't want those occurrences. The logic I am using may be summarized like so: if( ($textarea_line =~ m/^\s*(Exhibit\s+[\d.]+(\s*\([0-9a-zA-Z]+\))*)\s*$/i) || ($textarea_line =~ m/^\s*(FORM\s+10\-K)\s*$/i) || ($textarea_line =~ m/^\s*(FORM\s+10\-K[A-Z]*\/*[A-Z]*)$/i) || ($textarea_line =~ m/^\s*(FORM\s+8\-K)\s*$/i) ) I was using the index function to get the position of the particular heading that triggered the match: $heading = $1; $heading_offset = index($textarea, $heading); Being the rocket scientist I am, it took me all morning to figure out why I was getting inaccurate results. Then I finally went back to the manual and re-discovered that index returns the position of the FIRST occurrence of substring within string. First occurrence doesn't help me. I need, naturally, the exact occurrence (whether the fifth or the hundredth) that triggered the match. Any suggestions? -- Craig ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs