Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Code question

Options
  • 24-11-2009 11:09pm
    #1
    Registered Users Posts: 465 ✭✭


    Hey

    Using Perl and trying to do the following.

    I am trying to use the match and swap command.
    I want to match the following "\U+0027." and replace it with an
    apostrophe " ' "

    I have tried this and a few variations of this but it does not work fully

    if ($_ =~ m/\Q\U+0027.\E/ig){
    $_ =~ s/\Q\U+0027.\E/'/g;
    }

    Anyone any ideas what I am leaving out?

    Cheers


Comments

  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    you need to escape the "\" if you want to match it.

    "/\U" otherwise it thinks \U is a special character.


  • Registered Users Posts: 465 ✭✭coco06


    you need to escape the "\" if you want to match it.

    "/\U" otherwise it thinks \U is a special character.

    I tried doing this like this but I dont know where to put the corresponding slash.

    if ($_ =~ m/\Q/\U+0027.\E/g){
    $_ =~ s/\Q/\U+0027.\E/'/g;
    }


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    sorry gave you the wrong escape sequence.

    to match a "\" you need to preceed it with a "\" not "/" as i posted earlier i.e. "\\U"


  • Registered Users Posts: 465 ✭✭coco06


    sorry gave you the wrong escape sequence.

    to match a "\" you need to preceed it with a "\" not "/" as i posted earlier i.e. "\\U"

    cheers


  • Registered Users Posts: 5,112 ✭✭✭Blowfish


    Silly question, but how come you are using both a match and a swap? Surely the match is redundant?


  • Advertisement
Advertisement