This is exactly the direction I was thinking of going! Thanks!!! I will be digesting this

The problem I'm having is that I (re)process the string multiple times. That worked okay when I was doing it a few times -- perhaps several hundred or thousand times, total, in a run. But my best guess is that it will be run something between 1,500k and 3,000k times per run. Hence my hope for ideas on a better way.

Just for giggles and grins, I extracted the function I had into a standalone test script. It was probably at the top of my coding about 15+ years ago. Here it is:

#!/usr/bin/env perl my $which = 3; my $div = '!!!'; my $str = 'asdf' . $div . 'qwer' . $div . 'zxcv' . $div . 'hjkl' . $di +v . 'yuio' . $div . 'vbmn'; my @stuff; my $spot = 0; my $result = index($str, $div, $spot); print "str: [$str]\n"; while ($result != -1) { print "Found '$div' at $result\n"; my $start_spot = ($spot ? $spot + length($div) - 1 : 0); my $field_length = ($spot ? $result - $spot - length($div) + 1 : $ +result - $spot); push @stuff, substr($str, $start_spot, $field_length); $spot = $result + 1; $result = index($str, $div, $spot); } print @stuff . "\n"; print '-- #' . $which . '=' . @stuff[$which-1] . "\n";

I am continually amazed and pleased at the quality of the responses I get/see here on perlmonks! Thanks, y'all!!!

Lee Crites
lee@critesclan.com

In reply to Re^2: nth field extraction by lee_crites
in thread nth field extraction by lee_crites

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.