this is a basic, apprentice level question, but:
am processing a bunch of xhtml files to wml format and i want to find out how i can get the value of a pattern into a variable and then
interpolate this variable where needed.
files i'm processing appear thus:
<img src="xhtml/img/cancel.gif" width="24" height="13" alt="Cancel" /
+>
<textarea type="text" value="foo" name="text_message" /> <%bar%>&
+nbsp;</p>
what i want to do, and can't, is cut
/<%bar%>/and put it into
/foo/ while replacing
/textarea/ with
/input/
here's where i've got to:
foreach $file (@files) {
$file_new = $file;
open(IN, $file_new);
$content = <IN>;
$content =~s/xhtml/wml/g;
#...do lots more swopping here...
$content =~s/<h1>/<p><b>/g;
# now i want to replace /textarea/ below with /input/ and also tak
+e /<%bar%>/ and put it into /foo/
# trying something like this- doesn't work
while ($content =~ m/\(<textarea.*?>\)/sg) {
my $match = $1; $match =~ s/\n//g;
print " MATCH $match\n";
if($bar=~m/<%*?%>/){
$foo =~ m/foo/;
$value_of_bar = $bar;
# how to get $bar into $foo?
$content =~ s/$foo/$bar/g;
}
}
# write $content to file
open(OUT, ">$ARGV[1]/$file_new") || die "cannot open $ARGV[1]/$file_ne
+w";
print $content;
print OUT $content;
many thanks!
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.