How to view the code block genereated by n or p sw

2019-01-25 22:12发布

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.

2条回答
Bombasti
2楼-- · 2019-01-25 22:36

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
查看更多
叼着烟拽天下
3楼-- · 2019-01-25 22:49

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

perl -MO=Deparse -ne 'print if /^00/'
查看更多
登录 后发表回答