in reply to Prettyprint

Thanks everyone. Deparse works except for one odd feature. If I define a subroutine sub mysub{} at the bottom of my file then the Deparser changes the

mysub(myparam)

calls to

mysub myparam

and the calls to mysub then break. If I put the parentheses back in then the prettified code works great.

Replies are listed 'Best First'.
RE: Re: Prettyprint
by cianoz (Friar) on Sep 09, 2000 at 01:13 UTC
    what about "
    perl -MO=Deparse,-p yourscript.pl
    "? this should put a _lot_ of parentheses...
RE: Re: Prettyprint
by Adam (Vicar) on Sep 09, 2000 at 00:15 UTC
    That's somewhat odd. What does mysub{} do?
    Deparse is actually returning the interpreter's version of your code to you, so it will have some amount of inlining performed and a few other things specific to the state of your code when you deparsed it. In other words, your code will be slightly optimized and you should beware of early optimization. Perhaps I should have phrased my earlier statement:

    The deparser, when it works, returns (more or less) your code in a pretty format.

      mysub{} prints HTML code. Just one of life's mysteries, I guess.

      I read that in Perl the parentheses surrounding a subroutine's arguments are completely optional, so it should not matter whether I use parentheses to call subroutines in my prettified code, but it does.
        Wrong! Those parentheses are not "completely optional!"
        Parentheses are required when clarification is required. For example, if you don't prototype your subroutine, then you must use either an ampersand & or parentheses to tell Perl that its a user defined subroutine. You are probably not using strict or warnings, so the bareword message probably slipped past you unnoticed. I'm not sure why the deparser would drop the parentheses, but it makes sense that you would need them.
RE: Re: Prettyprint
by tye (Sage) on Sep 09, 2000 at 00:22 UTC

    Sounds like Deparse could use a patch, though I don't think it ever was intended to be used as a pretty printer. I bet you'll run into other output from Deparse that isn't working code as well.

            - tye (but my friends call me "Tye")