Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Automate perltidy for PM code?

by derby (Abbot)
on Jul 09, 2007 at 14:28 UTC ( #625617=note: print w/replies, xml ) Need Help??

in reply to Automate perltidy for PM code?

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



#!/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."


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://625617]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2018-05-23 04:13 GMT
Find Nodes?
    Voting Booth?