in reply to Best practices and any way to have Perl Tidy clean it up

You want a sub-tidy which formats embedded strings and here-docs?

I'm not aware of any possibility in perltidy for hooking an external parser for languages like SQL.

And how is tidy supposed to know what kind of sub-language you are using? Heuristics?

My best practice for embedded code is to manually change the mode in emacs and start a reformatting process on selected regions. When needed I even put this in a macro assigned to a key.

Cheers Rolf

( addicted to the Perl Programming Language)

  • Comment on Re: Best practices and any way to have Perl Tidy clean it up

Replies are listed 'Best First'.
Re^2: Best practices and any way to have Perl Tidy clean it up
by walkingthecow (Friar) on Apr 13, 2013 at 14:22 UTC
    Alright, assuming Perl Tidy cannot do this, then my next question is, what are the best practices for object parameters? For example:
    my $blah=$ldap->new( PARAM1 => $param1, PARAM2 => $param2, PARAM3 => $param3, );
    or:
    my Ssth = $dbh->prepare( "SELECT * FROM DATABASE WHERE name = '$name' AND money = '$money' AND field = '$field' ");
    I'm trying to get a feel for how deal with this formatting. Amount of spaces for what's within the parentheses; do the parentheses line up? And so on. I know it's a rather stupid question, but after all these years it's something that is still bothering me. I format everything else beautifully, but when it comes to this I have always been rather clueless.
      Since this is for the most part a personal preference there is no single correct answer, but my choice of formatting usually goes like this:
      my Ssth = $dbh->prepare(q( SELECT * FROM DATABASE WHERE name = ? AND money = ? AND field = ? )); $sth->execute($name, $money, $field);

      To be honest, I place the parantheses like you do, and leave the rest to Emacs' Perl mode.

        Additionally cperl-mode has a command to wrap long regions mapped on M-q plus an extra cperl-fill-paragraph command for comments.

        I rarely use perl-tidy, emacs has almost all of it included.

        And this kind of formatting can at best be semi-automatic since human monitoring is needed.

        Cheers Rolf

        ( addicted to the Perl Programming Language)