
LeoF
Novice
Sep 8, 2000, 11:21 PM
Post #1 of 4
(1560 views)
|
|
Using ? : inside RegExp
|
Can't Post
|
|
Hello everyone, Could someone be so kind as to help me with this? I'm working on modifying a smilies sub routine for a bulletin board, I would like for it to do the conversion to the IMG tag if and only if that image file exists, otherwise leave it untouched. Here is what I tried: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> $avl_smilies = "smile bigsmile laugh wink mad cool rolling tongue sad cry afraid"; # $test = "Testing testing :smile: testing testing :mad: testing testing :cool:"; # #if I try this it will always go to the else part $test =~ s,(\ (\S+?)(\ ,$2 =~ $avl_smilies ? <IMG SRC=\"/graphics/ $2.gif\"> : $2,isge; # #if I try this I get: # Testing testing IMG testing testing SRC=/graphics/.gif testing testing :cool: $test =~ s,(\ (\S+?)(\ , $avl_smilies =~ $2 ? <IMG SRC=\"/graphics/$2.gif\"> : $2,isge; </pre><HR></BLOCKQUOTE> It seems as if $2 is being modified but I don't know where, then I tried: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> @avl_smilies = qw(smile bigsmile laugh wink mad cool rolling tongue sad cry afraid); # $test =~ m,(\ (\S+?)(\ ,is; foreach (@avl_smilies) { if ($2 eq $_) { $test =~ s,(\ (\S+?)(\ ,<IMG SRC=\"/graphics/ $2.gif\" ALT=\" \">,is; last; } }</pre><HR></BLOCKQUOTE> and it works as intended but does it only for the first occurrence of a smilie, and I think is very inefficient. Also if I try: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> $test =~ s,(\ (\S+?)(\ ,$2 =~ $avl_smilies ? <IMG SRC=\"/graphics/ $2.gif\"> : \:$2\:,isge;</pre><HR></BLOCKQUOTE> To leave the original value as it was, I get an error message. I've been working on this for so many hours that I don't know what else to try, and I don't even know where the error is coming from. Any comments and suggestions would be very appreciated. Thanks in advance for your cooperation. Be Well
|