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

Does the Perl equivalent of the 'indent' program, or anything similar that can automatically indent my Perl code for me, exist?

Replies are listed 'Best First'.
Re: indent for Perl?
by pc88mxer (Vicar) on Jul 03, 2008 at 22:51 UTC
    Check out Perl::Tidy. You can also integrate it into vim and emacs to have it reformat the current buffer or selected region. For emacs integration, see EmacsWiki: CPerlMode
Re: indent for Perl?
by andreas1234567 (Vicar) on Jul 04, 2008 at 04:52 UTC
    I use emacs with cperl-mode and perltidy. I've added the following to my .emacs file:
    (defun perltidy () "Run perltidy on the current region or buffer." (interactive) (save-excursion (unless mark-active (mark-defun)) (shell-command-on-region (point) (mark) "perltidy --profile=/home/ +foo/.perltidyrc -q" nil t))) (global-set-key [(f5)] 'perltidy)
    Then I simply mark a region and press F5 to indent it nicely (according to my settings in the /home/foo/.perltidyrc file.
    --
    No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]
Re: indent for Perl?
by talexb (Chancellor) on Jul 04, 2008 at 18:56 UTC

    I use gvim which has syntax colouring and indenting for dozens of languages, including Perl. In addition, I run chunks of code (or sometimes the entire file) through perltidy.

    I prefer an initial indent of 4, with subsequent indents of 2, but I can live with perltidy's default setting of 4+4.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds