The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

I'm writing a program in which semi-colins ( 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 \ . 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!

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 &nbsp; 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!

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.

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.