Thread: perl var issue

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    3
    Rep Power
    0
    hi..
    how can I do this:
    $inVar = "this is a string with both " and ' in it which will probably confuses the perl engine";

    I could have added slashes by hand.. but the above string is 2000 lines long in my program..
    I tried using quotemeta but it didn't work either...
    no.. I don't want to store it in a file.. and then do it..
    I want to be able to do this within the same file...

    how can it be done?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    81
    Rep Power
    15
    Use:
    $inVar = qq/this is a string with both " and ' in it which will probably confuses the perl engine/;
    If you have / characters occuring in your string, use some other delimiter (e.g ~ or !) -- basically, just pick some non-whitespace, non-alphanumeric character that doesn't occur in your string. If there is no such character, then you'll have to escape any characters that match your delimiter (i.e. if you use " as a delimiter you must replace all occurences of " in the string with ", or if you use / you'd have to replace it with /).

    One note is that if you're not interpolating variables in that string, you should use single quotes or the q// operator, as that doesn't attempt to do any variable interpolation and so runs a lot faster. If you don't entirely understand what I'm talking about, run:
    perldoc perlop
    and go to the section entitled:
    Quote and Quote-like Operators

IMN logo majestic logo threadwatch logo seochat tools logo