Perl函数string2hex

use*_*240 3 perl

我有一个功能:

sub ascii_to_hex ($)
{
    ## Convert each ASCII character to a two-digit hex number.
    (my $str = shift) =~ s/(.|\n)/sprintf("%02lx", ord .$1)/eg;
    return $str;
}
Run Code Online (Sandbox Code Playgroud)

我需要在每个数字前加上'%'.领取%68%75%44

cho*_*oba 11

%%用于sprintf格式字符串以打印百分号.