http://www.perlmonks.org?node_id=625617


in reply to Automate perltidy for PM code?

No need for piping through perltidy, Perl::Tidy with the right config can do the trick.

-derby

Update:

#!/usr/bin/perl use strict; use warnings; use Perl::Tidy; my $input = <<'_EOT'; sub Tidy { my ( $text, $cmdopt ) = @_; my $tmpfile = "/tmp/Tidy.$$." . join( '', localtime()) ."tmp"; open my $th, ">$tmpfile" or die; print $th $text or die; close $th or die; my $pid = open my $ph, "perltidy -st $cmdopt $tmpfile |" or die; my $tidied = join '', <$ph>; close $ph or die; waitpid $pid, 0; unlink $tmpfile; return $tidied; } _EOT my $output; Perl::Tidy::perltidy( source => \$input, destination => \$output, ); print $output;

Replies are listed 'Best First'.
Re^2: Automate perltidy for PM code?
by Moron (Curate) on Jul 09, 2007 at 15:35 UTC
    Yes, thanks for that CPAN link. One thing I notice with a wry smile is that when you cut and pasted my hand-written effort you lost the original tabbing on the repaste, this being a perfect example of the kind of problem I am talking about and one that happened to be in my mind when I wrote the OP! That's the second time within a week I notice that replies to the OP serve themselves as entirely accidental examples of what the OP is talking about - - spooky! Even more spooky when you consider that both cases were your replies to my OPs - hmmm what does that mean?
    __________________________________________________________________________________

    ^M Free your mind!

      It means I got my eye on you Moron! Just kidding. For this thread, I did purposefully delete your leading spaces just to show that Perl::Tidy does the job - if I left the code alone, I believe the output from perltidy would have been identical to your original code. As for Forthcoming attraction - "Positive fast, negative slow"? ... well lets just say my attempts at sarcasm and humor did not go over well - I knew I should've said "I can't get past the first paragraph ... so I downvoted."

      -derby