How to view a block of code genenerated with an n or p switch in perl one liner

I'm sure I've run this before, but throughout my life I can't seem to find links to perlrun or via google. Hopefully some of them will answer it. When starting perl, one liner with the -ne switch. Is there an option so that the code that perl will compile is output to the console?

So, if I run:

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

      

Then Perl will compile this:

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

      

I'm sure there is a way to make Perl spit out the code it is about to use, including any start or end blocks. hope someone knows how.

+3


source to share


2 answers


You may be thinking about B::Deparse

:



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

      

+10


source


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


source







All Articles