Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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.

-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;


Comment on Re: Automate perltidy for PM code?
Download Code
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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-10-24 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (131 votes), past polls