SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    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!

  2. #2
    SitePoint Zealot
    Join Date
    Nov 1999
    Location
    Manhattan!
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What language are we talking about?

    Christian

  3. #3
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh. That'd be important.

    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!

  4. #4
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  5. #5
    SitePoint Zealot
    Join Date
    Nov 1999
    Location
    Manhattan!
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  6. #6
    Destiny Manager Plebius's Avatar
    Join Date
    Nov 1999
    Posts
    682
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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);

  7. #7
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •