user2000 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Please look at the link below: https:\x2F\x2Fwww.google.com\x2Faccounts\x2FCheckCookie?chtml=LoginDoneHtml How should I convert \x2f to "/"? Also how does it work? The line below does not work: $s = s/\x2f/\//igs; After I LWP get a page, do i need to process it in anyway to convert hex to something? is there any sort of conversion required? What about urls? are they encoded in any way? Thank you, Anant

Replies are listed 'Best First'.
Re: Urls & Perl
by FunkyMonk (Bishop) on Aug 11, 2007 at 19:12 UTC
    You need to quote the backslash. I've used \Q below. \Q (quotemeta) is described in Regular Expressions.

    $_ = '\x2f\x2f\x2f' . "\n"; print; print "Matched\n" if s/\Q\x2f/\//igs; print; __END__ \x2f\x2f\x2f Matched ///

    update: added link to \Q

Re: Urls & Perl
by wind (Priest) on Aug 11, 2007 at 20:52 UTC

    As FunkyMonk already pointed out, you need to escape the backslash in your regular expression. Otherwise \x2f is interpolated as the hex character 2F, which is "/".

    You could easily make this translation generic if there are other characters that might be escaped.

    my $str = 'https:\x2F\x2Fwww.google.com\x2Faccounts\x2FCheckCookie?cht +ml=LoginDoneHtml'; $str =~ s{\\x([0-9a-fA-F]{2})}{chr hex $1}eg; print $str;
    - Miller
      thank you very much. it worked great. but i dont know why its not working for: \u300d which should get converted to = thank you
Re: Urls & Perl
by ysth (Canon) on Aug 12, 2007 at 06:17 UTC
    Also how does it work?
    If you're asking why there are literal \x2F's in place of the slashes in your url, you should tell us where you got the url from.

    You shouldn't need to process or convert a page fetched by LWP, no. Is there something that makes you think you do need to?

      I got the link with \2xf from the orkut login website. When you login, you are redirected to a page containing \x2f which further redirects to a link containing \u300d. Thank you