Ha! Got another solution. Using what chromatic previously suggested. I discovered that it is working, but it is ignoring the space in the '$1 ', so the string is not modified. However, if the replacement string is specified as '$1." "', because the /e modifier evalutes it as a Perl expression, it correctly puts the space after the value of $1.

So here's another version that works:

#!/usr/bin/perl my $string="realllylongstringthatrefusestoend <A HREF=\"http://perlmo +nks.org/images/blah/blah/blah\">\n"; print splitter($string,"<.*?>",'(\S{18})','$1." "'); sub splitter{ my($string,$spliton,$find,$replace)=@_; my @array=split(/$spliton/,$string); my $i=0; my @splitters; my $str; while($string=~/($spliton)/g){ push @splitters,$1; } for (@array){ s/$find/$replace/eeg; ; $str.=$array[$i]; $str.=$splitters[$i]; $i++; } $str; }
I believe this has the same security problems as evaluating with double quotes, because it allows the execution of arbitrary perl code.

--ZZamboni


In reply to RE: Handling scalars as regexs within a substitution. (Take 2) by ZZamboni
in thread Handling scalars as regexs within a substitution. (Take 2) by vroom

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.