How to view the code block genereated by n or p switch in perl one liner

自闭症网瘾萝莉.ら 提交于 2019-11-28 01:46:57

问题


I am sure I have run this before but for the life of me cant find any reference in perlrun or through Google. Hopefully some of the perl boffins here will be able to answer it. When running a perl one liner with the -ne switch. Is there an option to have the code, that perl will compile, to be outputted to the console?

So if I run:

crontab -l | perl -ne 'print if /^00/'

Then Perl will compile this to:

while(<>){
   print if /^00/;
}

I am sure there is a way to have perl spit out the code its going to use including any begin or end blocks. hopefully someone knows how.


回答1:


You may be thinking of the B::Deparse function:

perl -MO=Deparse -ne 'print if /^00/'



回答2:


Try

perl -MO=Deparse -ne 'print if /^00/'

It will give you the output like this:

LINE: while (defined($_ = <ARGV>)) {
    print $_ if /^00/;
}
-e syntax OK


来源:https://stackoverflow.com/questions/25911424/how-to-view-the-code-block-genereated-by-n-or-p-switch-in-perl-one-liner

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!