-
Hello,
I'm writing a program in which semi-colins ( http://www.webmaster-resources.com/forums/wink.gif are used to end a statement. However, sometimes I want to put a semi-colin in where I don't want a end statement. In this case I simply precede it with a \ (ie \ http://www.webmaster-resources.com/forums/wink.gif. Then, when the program is run the \; is replaced with an unlikely squence of characters (%^). Then replaced again when the output is created.
Does anyone know of a better method to do this? It seems awfully inefficient.
Thanks!
Owen
------------------
uDiscuss.com - the most advanced forums on the Internet!
-
What language are we talking about?
Christian
-
Oh. That'd be important. http://www.webmaster-resources.com/forums/smile.gif
Perl, is my language of choice.
To be exact, the command I use is:
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code:</font><HR><pre>
$line =~ s/\\;\\^\^/g; # convert \; to ^^ to be reconverted later.
[/code]
The reverse for backwards, of course...
Thanks!
Owen
------------------
uDiscuss.com - the most advanced forums on the Internet!
-
The reason I convert the string is that a ; is the end of line terminator. My program does a split on the ; character. (In html you might want to output so I would need to convert it so the program doesnt end the statement there.)
I just think it is confusing using some other character for ; (I guess I should say that my project is a HTML converter...)
Owen
------------------
uDiscuss.com - the most advanced forums on the Internet!
-
Hello again.
First off, yes -- it does seem pretty ineffecient.
I persume the semi-colon appears inside a text string. So, why do you replace it after escaping it? I would think that once you have escaped the ; the text should be fine?
If not, why not just write semi-colons directly as some char string (i.e. #@#) and then replace them on execution? If you do the replace anyway, there should be no reason to escape them in the beginning.
Christian
-
If the other semicolon you don't escape comes only at the end of a line, you can make something like this to get the lines, then you wouldn't even need to escape the other semicolon. You could also use some other sequence of charachters to represent a semicolon in the first place, like ':::' or something.
@lines = split(/;\n/, $TEXT);
-
True. true. I allow multi-line statements... I guess I'll have to use another character for ;. Too bad there is no function in perl for treating escaped characters as different from non-escaped.
Thanks everyone!
Owen
------------------
uDiscuss.com - the most advanced forums on the Internet!