regex replace hex with &#ddd;

Discussion in 'Perl Misc' started by John, Nov 10, 2009.

  1. John

    John Guest

    Hi

    $x =~s |([xc0-xff])|\&\#ord($1)\;|eg;

    I'm trying to replace any character C0 to FF with

    I cannot get the ord to evaluate. I have appended the 'e'

    Any idea what I'm doing wrong?

    Regards
    John
    John, Nov 10, 2009
    #1
    1. Advertising

  2. John

    Guest

    On Tue, 10 Nov 2009 14:51:00 -0000, "John" <> wrote:

    >Hi
    >
    >$x =~s |([xc0-xff])|\&\#ord($1)\;|eg;
    >
    >I'm trying to replace any character C0 to FF with
    >
    >I cannot get the ord to evaluate. I have appended the 'e'
    >
    >Any idea what I'm doing wrong?
    >
    >Regards
    >John
    >

    When its evaled it needs to be quoted.
    Don't forget to escape the hex notation.

    $x = "\xc0 \xff";
    $x =~s |([\xc0-\xff])|'&#'.ord($1).';'|eg;
    print $x;

    -sln
    , Nov 10, 2009
    #2
    1. Advertising

  3. John

    John Guest

    <> wrote in message
    news:...
    > On Tue, 10 Nov 2009 14:51:00 -0000, "John" <> wrote:
    >
    >>Hi
    >>
    >>$x =~s |([xc0-xff])|\&\#ord($1)\;|eg;
    >>
    >>I'm trying to replace any character C0 to FF with
    >>
    >>I cannot get the ord to evaluate. I have appended the 'e'
    >>
    >>Any idea what I'm doing wrong?
    >>
    >>Regards
    >>John
    >>

    > When its evaled it needs to be quoted.
    > Don't forget to escape the hex notation.
    >
    > $x = "\xc0 \xff";
    > $x =~s |([\xc0-\xff])|'&#'.ord($1).';'|eg;
    > print $x;
    >
    > -sln


    Many thanks. I completely messed up the second half. But I see the
    solution now.

    Regards
    John
    John, Nov 10, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    6,132
    Neredbojias
    Aug 19, 2005
  2. John
    Replies:
    1
    Views:
    512
    Jack Klein
    Apr 14, 2004
  3. Victor

    DDD or Insight?

    Victor, Apr 15, 2004, in forum: C++
    Replies:
    0
    Views:
    370
    Victor
    Apr 15, 2004
  4. Victor

    ddd or insight?

    Victor, Apr 16, 2004, in forum: C++
    Replies:
    2
    Views:
    1,493
  5. Bengt Richter
    Replies:
    6
    Views:
    448
    Juha Autero
    Aug 19, 2003
Loading...

Share This Page