我在perl中使用
regex将字符串转换为十六进制,但是,当我这样做时,我会收到来自perl评论家或perl的警告:
#$test is defined,i just put the regex code snippet here... #this will trigger a warning from perl critic #warning: use of regex expression without "/x" expression.. $text =~ s/(.)/sprintf("%x",ord($1))/eg; #this will trigger a a warning at run time #warning: "uninitialized value $1 in regexp compilation" $text =~ m{s/(.)/sprintf("%x",ord($1))/eg}x;
有没有办法编写上面的代码,没有得到Perl评论家的警告或反馈?
我认为问题是因为ord正在处理未定义的值,当你输入/ x时,检查regex表达式认为$1的值是无效的.