hello,
i'm trying to extract a pattern from a string, hold it in a variable, and then use this variable in a substitution.
in the code below, i extract $match from $content(which is a string holding the entire file contents).
i then extract $varmatch from $match, which i try to use in a substitution thus:
$match=~ s/$varmatch//g;
to remove $varmatch from $match.
i then insert it at another point in $match.
the strange thing is, i can use $varmatch and
insert its value into the containing string
(
$match=~ s/textarea/testinsert$varmatch/g;), but can't use it to
remove its value from the containing string.
i'm still pretty new to the wonders of perl, so i may be missing something obvious.
oh, and i've tried using pos() to position the cursor back to the beginning of $match, (
pos $match = 0; ) but to no avail.
any monkly wisdom on this received with gracious thanks :)
Z.
while ($content =~ m/(<textarea.*textarea>)/sg) {
my $match = $&;
my $varmatch;
print "match: before ..... $match\n";
if( $match =~ m/(<%=.*?%>)/sg){
$varmatch = $1;
print "varmatch: $varmatch\n";
pos $match ;
#cut var tag
$match=~ s/$varmatch//g;
print "match: after .... $match\n";
$match=~ s/textarea/testinsert$varmatch/g;
print "match: after testinsert .... $match\n";
...program continues here
program output:
---------- perl ----------
varmatch: <%=foo::doSomething%>
match: before .... <textarea class="FolderTxtArea" name="blah"><%=foo:
+:doSomething%></textarea>
match: after .... <textarea class="FolderTxtArea" name="blah"><%=foo:
+:doSomething%></textarea>
match: after testinsert .... <testinsert<%=foo::doSomething%> ...
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.