fionbarr has asked for the wisdom of the Perl Monks concerning the following question:

Is there a flag for B::Deparse that retains comments? Or another method of parsing Perl code that keeps comments?

Replies are listed 'Best First'.
Re: B::Deparse (with comments)
by LanX (Saint) on Feb 16, 2015 at 20:43 UTC
    > Is there a flag for B::Deparse that retains comments?

    no¹, but -l will point you to the original source line

    -l Add '#line' declarations to the output based on the line and file +locations of the original code.

    for instance

    perl -MO=Deparse,-l tst_glob.pl #line 1 "tst_glob.pl" $\ = "\n"; #line 3 "tst_glob.pl" $n = 123; #line 5 "tst_glob.pl" $gr = \*n; ...

    so just write yourself a post processor script to reinclude the missing lines as comments or POD or here-docs or whatever.

    I recommend using Perl, it's good at text processing. ;-)

    Cheers Rolf

    PS: Je suis Charlie!

    ¹) IIRC does B::Concise have an option to include original code... (update: yes -src )

Re: B::Deparse (with comments)
by toolic (Bishop) on Feb 16, 2015 at 20:28 UTC