On Aug 1, 8:55 pm, "attn.steven....@gmail.com"
<attn.steven....@gmail.com> wrote:
> On Aug 1, 1:02 pm, surfitupdot...@gmail.com wrote:
>
> (snipped)
>
>
>
> > You read me correctly, idea was tospliton any occurrence of my
> > search term that does not have an underscore before or after it.
> > Counting matches usingsplitworked fine until I tried to exclude
> > certain patterns. I will look at the perldoc you suggested but here
> > is more info for the thread. Thanks, John
>
> > Sample input: super _super_ _super super SUPER SUPER_ blahsuper
> > Desired output: super super SUPER super
>
> How did you plan on getting rid of the 'blah' substring by
> doing asplit?
>
>
>
> > Current output usingsplit(/(?<!_)${search_term}(?!_)/i, $grep_out);
> > Array contents- _super_ _super SUPER_ blah
>
> Your description said 'a underscore before ... OR
> a underscore after'; so you also need an "OR" in your
> regular expression. This is known as "Alternation"
> (see perldoc perlre).
>
> use Data:
umper;
>
> my $term = 'super';
>
> my $string = 'super _super_ _super super SUPER SUPER_ blahsuper';
>
> my @fragments =split(
> /_\Q$term\E_? # exclude term with underscore in front
> # (optional trailing _)
> | # OR
> _?\Q$term\E_/xi # exclude term with underscore afterward
> # (optional leading _)
> , $string);
>
> print Dumper \@fragments;
>
> __END__
>
> I get:
>
> $VAR1 = [
> 'super ',
> ' ',
> ' super SUPER ',
> ' blahsuper'
> ];
>
> Is that what you wanted? As Paul said, there's
> probably a better way to "count" things than
> usingsplit.
>
> --
> Hope this helps,
> Steven
Thanks all for the assist. After further experimentation I did switch
to using option other than split for this task. I did sharpen my
regexp along the way so everything worked out. Take care, John