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

2019-01-25 22:11发布

问题:

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