perl - escape ampersand in string

Discussion in 'Programming' started by popowich, Mar 13, 2009.

  1. #1
    Hello,

    I have a perl script that reads data from a file.

    Some of the data has &'s in it. I need it treated as regular text.

    The fact that it's in strings doesn't seem to be a problem, but passing that string into part of a system(); command is causing me a problem.

    The & might be anywhere in the string.

    What's the proper way to handle this in perl? Thanks!

    -Raymond
     
    popowich, Mar 13, 2009 IP
  2. popowich

    popowich Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Eh, escaping it in the original data file seems to do the trick instead of trying to fix it while inside the perl script.

    -Raymond
     
    popowich, Mar 13, 2009 IP
  3. REALLY Made IN Canada

    REALLY Made IN Canada Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The important starting point is to ensure you are "encoding" the correct level of information.

    - HTML entities (such as quot, apos)
    - URLs (with ampersand as parameter separator)
    - Escaped chars (more at coding level such as quotes, pipe chars etc).

    Then you need to "encode it" it appropriately for the destination (is it in a string, MYSQL data record, printed on a web page).

    Sometimes, a string may be encoded several times before it is decoded - keeping track is important as well.
     
    REALLY Made IN Canada, Mar 15, 2009 IP