奇怪的perl代码-寻找解释

奇怪的perl代码-寻找解释,perl,obfuscation,Perl,Obfuscation,我懂一点perl,但还不足以深入理解下一个 在阅读中,我发现了下一段代码,即5.18中已经禁用的代码。不算这些,我还是想知道它是怎么工作的 这是代码,在注释中是我理解的 %_=(_,"Just another "); #initialize the %_ hash with key=>value _ => 'Just another' $_="Perl hacker,\n"; #assign to the $_ variable with "Perl..." s//_}-&

我懂一点perl,但还不足以深入理解下一个

在阅读中,我发现了下一段代码,即5.18中已经禁用的代码。不算这些,我还是想知道它是怎么工作的

这是代码,在注释中是我理解的

%_=(_,"Just another "); #initialize the %_ hash with key=>value   _ => 'Just another'
$_="Perl hacker,\n";    #assign to the $_ variable with "Perl..."
s//_}->{_/e;            # darkness. the /e - evauates the expression, but...
print
它打印:

Just another Perl hacker,
我尝试了,perl-MO=Deparse并得到了下一个

(%_) = ('_', 'Just another ');   #initializing the %_ hash
$_ = "Perl hacker,\n";           # as above
s//%{'_';}/e;                    # substitute to the beginning of the $_ - WHAT?
print $_;                        # print the result
japh syntax OK
奇怪的是(至少对我来说)-运行“deparsed”代码不会给出原始结果并打印:

1/8Perl hacker,
我会非常高兴:

  • 如果有人能解释代码,特别是如果有人能写一个助手代码,(通过额外的步骤)什么能帮助我理解它是如何工作的-发生了什么
  • 解释,为什么被删除的代码不打印原始结果

  • 什么意思是deparsed代码中的
    %{''.}

    my $code = "do { $repl_expr }";
    
    因此,当替换表达式为
    \}->{
    时,将执行以下操作:

    do { _}->{_ }
    
    \uu
    只返回字符串
    \u
    (因为strict是关闭的),所以这与

    do { "_" }->{_}
    
    "_"->{_}
    
    $_{_}       # Compile-time symbol lookup
    
    这和

    do { "_" }->{_}
    
    "_"->{_}
    
    $_{_}       # Compile-time symbol lookup
    
    这里有一个散列元素取消引用,其中引用是一个符号引用(即字符串而不是实际引用)。通常严格禁止,下面是一个符号引用的示例:

    %h1 = ( id => 123 );
    %h2 = ( id => 456 );
    print "h$_"->{id}, "\n"
       for 1..2;
    
    这意味着

    "_"->{_}    # Run-time symbol lookup
    

    do { "_" }->{_}
    
    "_"->{_}
    
    $_{_}       # Compile-time symbol lookup
    

    一行程序中经常使用类似的技巧

    perl -nle'$c += $_; END { print $c }'
    
    可以缩短为

    perl -nle'$c += $_; }{ print $c'
    
    因为使用
    -n
    时实际执行的代码是从与

    my $code = "LINE: while (<>) { $program }";
    
    %_
    
    这是一种非常奇怪的写作方式

    %{'_'}
    
    这是一个散列解引用。同样,这里的引用是一个符号引用。它等价于

    my $code = "LINE: while (<>) { $program }";
    
    %_
    

    在标量上下文中,hash current返回一个值,该值报告有关该hash内部的一些信息(如果为空,则返回一个假值)。有人建议将其更改为返回键数。

    我无法解释一切,但由于某种原因,
    ->{code>在正则表达式中相当于
    ${{{code}
    (这本身看起来很有趣,但也不太难理解)。我不明白的是箭头操作符是如何被吞并的,因为它只应该在
    $\uucode>是散列引用的情况下工作。因为它试图忽略
    do
    或由replacment表达式添加的任何内容,但最终忽略了其他内容,因为
    do
    不再是第一个操作。或者更一般地说s、 该代码创建了不应该存在的编译代码,因此Deparse所做的假设是失败的。