Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Your Favorite Options for Perltidy

by Anonymous Monk
on Nov 05, 2005 at 14:19 UTC ( #505984=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I want to improve in style while coding perl. I really want to know what's your favorite setting (option) when running perltidy command line?

Mine is probably too bland.
$ perltidy -b -bl -anl -i=4 myfile.pl

Comment on Your Favorite Options for Perltidy
Download Code
Re: Your Favorite Options for Perltidy
by ambrus (Abbot) on Nov 05, 2005 at 15:56 UTC

    I don't use perltidy. I do the formatting by hand, with some help from the editor.

      Perltidy can also be used for other things than code formatting. In fact, it can be bloody helpful. Take the following heartsinking error message:

      Missing right curly or square bracket at ccpd.pl line 1102, at end of +line syntax error at ccpd.pl line 1102 at EOF
      Bugger. So where is the missing curly brace? Dunno. Have no fear, for Perltidy will tell me in the error file it creates.
      The most recent un-matched '{' is on line 567 567: sub createAuthMessage {
      Now that rocks.

      -- vek --

        An editor can help there too: I jump to the EOF where the error appears, insert a closing brace, and jump to the matching brace.

        However, an even more efficent way to find the missing braces is when the interpreter guesses its place from the indentation of the code (even though the indentation has no semantical meanning). The MzScheme interpreter can do this, and usually guesses right. (I hope perl6 will be able to do this too.) If, however, you reformat the code with an indenter, then the indents will follow the braces you've put there, not the way you think the code should be indented, so then indentation can't provide a clue to the interpreter.

        That rocks indeed! What command do you use to generate that last message? And in what environment?
Re: Your Favorite Options for Perltidy
by sauoq (Abbot) on Nov 05, 2005 at 16:10 UTC
    $ cat .perltidyrc -ce -nsfs -isbc -olc
    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Your Favorite Options for Perltidy
by Aristotle (Chancellor) on Nov 05, 2005 at 16:28 UTC
    $ cat .perltidyrc 
    --indent-columns=4 --continuation-indentation=4 --maximum-line-length=80 --entab-leading-whitespace=4 --tabs --paren-tightness=0 --brace-tightness=0 --block-brace-tightness=0 --square-bracket-tightness=0 --nooutdent-long-quotes --indent-spaced-block-comments --outdent-long-comments --long-block-line-count=4 --maximum-consecutive-blank-lines=2 #=--standard-output #=--standard-error-output

    Makeshifts last the longest.

Re: Your Favorite Options for Perltidy
by borisz (Canon) on Nov 05, 2005 at 17:30 UTC
    -l=80 -ci=2 -i=2 -lp -nsfs -bar -bbb -bbs -bbc -anl
    Boris
Re: Your Favorite Options for Perltidy
by pboin (Deacon) on Nov 06, 2005 at 00:52 UTC
      Thanks so much. But when does .perltidyrc get executed?
      • automatically when we start a perl script? or
      • when we pass the command: $ perltidy myfile.pl ?

        Nothing's *automatic* per se. Perltidy is a filter that you run on source. As TheDamian has it setup, it will print to STDOUT, so you can do something like this:

        perltidy sloppy_format.pl > cleaned_up.pl

        .perltidyrc will be automatically called for configuration details. Once you get that figured out, you can even hightlight one block in vim and do "! perltidy" to cleanup just a block within a file.

        Good luck and perservere. Tidy code is a worthwhile endeavor, whether you create it that way or beat it into submission with a tool.

Re: Your Favorite Options for Perltidy
by Anonymous Monk on Oct 23, 2009 at 07:05 UTC
    perltidy now comes with option -pbp, --perl-best-practices
    -l=78 -i=4 -ci=4 -st -se -vt=2 -cti=0 -pt=1 -bt=1 -sbt=1 -bbt=1 -n +sfs -nolq -wbb="% + - * / x != == >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x="
Re: Your Favorite Options for Perltidy
by mje (Deacon) on Oct 23, 2009 at 09:42 UTC

    Anyone know what the perltidy option is to stop it lining up assignments?

    I prefer:

    $abcde = 1; $b = 1;

    but by default I get;

    $abcde = 1; $b = 1;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://505984]
Approved by ybiC
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (17)
As of 2014-09-23 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (234 votes), past polls