R
Robert Wallace
my program should replace
[ ] with a wingdings box
[*] with a wingdings checked box
[!] with another wingdings box
--> with a wingdings arrow
here's the hash:
%wingdings=(
'[*]' => '<font face="wingdings">þ</font>',
'[ ]' => '<font face="wingdings">o</font>',
'[!]' => '<font face="wingdings">q</font>',
'-->' => '<font face="wingdings">ð</font>',
);
sample string:
$x="[*] blah blah"
if sub called with:
print replace($x);
results:
0 [0] blah blah
since we can't display graphics, imagine 0 as the wingdings character
why do I get one item replaced twice. and why is one between the [ and
the ]?
sub replace {
while (($k,$v) = each %wingdings){
$str=~s/$k/$v/;
#print "key=$k, value=$v<br>\n"; # use for debuging
}
#print "$str<br>\n---------------------------<br>\n"; #use for
debuging
}
----------------------
and if the sample string is:
$x="[!] blah blah"
if sub called with:
print replace($x);
results:
[0] 0 blah blah
since we can't display graphics, imagine 0 as the wingdings character
why do I get one item replaced twice. and why is one between the [ and
the ]?
only, this time the [ and the ] are on the first replacement.
now if we set the s/// to do global replacement s///g, whoa!
we get every space replaced!
[ ] with a wingdings box
[*] with a wingdings checked box
[!] with another wingdings box
--> with a wingdings arrow
here's the hash:
%wingdings=(
'[*]' => '<font face="wingdings">þ</font>',
'[ ]' => '<font face="wingdings">o</font>',
'[!]' => '<font face="wingdings">q</font>',
'-->' => '<font face="wingdings">ð</font>',
);
sample string:
$x="[*] blah blah"
if sub called with:
print replace($x);
results:
0 [0] blah blah
since we can't display graphics, imagine 0 as the wingdings character
why do I get one item replaced twice. and why is one between the [ and
the ]?
sub replace {
while (($k,$v) = each %wingdings){
$str=~s/$k/$v/;
#print "key=$k, value=$v<br>\n"; # use for debuging
}
#print "$str<br>\n---------------------------<br>\n"; #use for
debuging
}
----------------------
and if the sample string is:
$x="[!] blah blah"
if sub called with:
print replace($x);
results:
[0] 0 blah blah
since we can't display graphics, imagine 0 as the wingdings character
why do I get one item replaced twice. and why is one between the [ and
the ]?
only, this time the [ and the ] are on the first replacement.
now if we set the s/// to do global replacement s///g, whoa!
we get every space replaced!