Thread: Perl Tidy Script dirk
Here is a simple script which takes a
Perlscript as input, parses and beautifies the sourceusing the module Perl::Tidy and writes the formated source to a new file.For example: input: test.pl output: test.pl.tdy #!/usr/bin/ perluse strict; use warnings; use Carp; use English; use Perl::Tidy;#------------------------------------------------------------------------------- my $script = 'test.pl'; my $argv = '-ci=4 -nolq'; # -nolq : No Outdenting Long Quotes # -ci=n, --continuation-indentation=n # input parameters as described in the perltidy(1) man page#------------------------------------------------------------------------------- open my $SCRIPT, '<', $script or croak "Can't open '$script': $OS_ERROR"; my $source = do { local $/; <$SCRIPT> }; close $SCRIPT; my @destination = undef; perltidy(source => $source, destination => @destination, argv => $argv, ); open my $TDYSCRIPT, '>', $script . '.tdy' or croak "Can't open '$script.tdy': $OS_ERROR"; foreach my $line (@destination) { print {$TDYSCRIPT} $line; } close $TDYSCRIPT; exit; perkiset
Nice - funny, I wrote a "tidy" script for Clipper (Summer '87) that I called... wait for it... "
Ajax- Code Cleaner" a long time ago. ALWAYS nice to have these about.../p thedarkness
Shame you didn't copyright the name.......
perkiset
Seems to me it was already taken back then as well
Dirk - looking back over the code and now beeing .00001% smarter in PERLbecause of you, I am not clear how this accomplishes anything... is TDYSCRIPT amacro or something?dirk
Ed, would not call it a
macro.It's simply a script written to use the standard PerlmodulePerl::Tidy.And it handles the input and output. You can execute the module directly on the command line, like: > perltidy -D filenameBut using a script, I think, is a little bit more comfortable. I run such scripts directly in my IDE, so I don't have to switch to the command line. perkiset
Thanks Dirk -
Yikes that syntax throws me off. nutballs
interesting. i have never once used a code formatter. my code is usually pretty well formatted, but other people's code drives me nuts. random indents, no indents, no line breaks between "concepts" etc. I might write one for
ASP. possibly a good exercise anyway.perkiset
Abalootly nuts - even if you write it in another language to format a new one you're working with... gives you a feel for the rhythm of a language really quickly.
|
Thread Categories
Best of The Cache Home | ||
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads