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

i read a cgi file from webpage, and hope can download it email adress, but unfortune the page that i download had use an encodeemail method, so i can't read the result file well, this is my program
#!C:\Perl\bin\perl.exe -w use strict; use warnings; use LWP::UserAgent; my $url = "http://bbs.wenjuantong.com"; open(OUT, ">>respone.txt") or die("Cannot open out file:$!"); my $agent = new LWP::UserAgent(); my $request = new HTTP::Request('get' => $url); $request ->content_type('application/x-www-form-urlencoded'); $request ->content('type=another'); my $response = $agent ->request($request); print(OUT $response->as_string()); print(OUT "\n"); close(OUT) or die("Cannot close out file:$!");
this is a encodeemail fuction, would you like help me write a decodeemail.
sub encodeemail{ my ($self, $email) = CGI::self_or_CGI(@_); my $char = ''; while ($email =~ /([a-z\@]{1})/is){ $char = '&#' . ord($1) . ';'; $email =~ s/$1/$char/sg; } return $email; }

Replies are listed 'Best First'.
Re: how to write a function to decode email
by davido (Cardinal) on Apr 27, 2006 at 06:17 UTC

    Because chr is the reverse of ord, a portion of the decodeemail() sub might look something like this:

    $email =~ s/&#(\d+);/chr($1)/eg;

    ...that is, if I understand the spec. But I suspect that you ought to use HTML::Entities or HTML::Entities::Numeric for both your encodeemail() and your decodeemail() subroutines anyway. It's more robust than the average home grown solution.


    Dave

      thanks for all of you answer, my problem have solve just follow you.
Re: how to write a function to decode email
by sgifford (Prior) on Apr 27, 2006 at 15:32 UTC
    The very purpose of encoding the email addresses is to make it difficult for screen-scraping programs, like the one you've posted, to harvest the addresses, possibly for spam. Can you explain briefly the legitimate reason you want to bypass these protections, and reassure us it's not to spam these users?
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: how to write a function to decode email
by chargrill (Parson) on Apr 27, 2006 at 06:14 UTC

    Are you looking for something like this:

    $email =~ s/&#([0-9]+);/chr $1/gem;


    --chargrill
    $,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}
    A reply falls below the community's threshold of quality. You may see it by logging in.