Gossamer Forum
Home : General : Perl Programming :

Formatting

Quote Reply
Formatting
Is there a script that formats a perl script?

I picked up a nice script that let's me check my pop mail from the browser for certain cases (like when I am on the go). I thought it would be a good idea. Anyways, the code looks real ugly. An entire subroutine if formatted GT style would be 30 some lines but they have it all on two or three lines.

Just wondering if there is a script that will reformat the script for me rather than going through it line by line. Not just by adding in newlines but also tabs and 2 newlines after completed else statements followed by more code.. Just the way most of us would probably want the code.

Is there? I'm probably going to start on one myself, but if there is one already done.. that'd be great too.

Thanks.

--
jsu
Quote Reply
Re: [Seto Kaiba] Formatting In reply to
after a few hours of work.. i'm getting somewhere with this.

the once.. 700+ line code i wanted reformatted is now 2061 lines long. it should be a bit shorter, but i left out a few things in the code when it scans the file section by section.

it's formatting a 50kb perl script file in about 16 seconds. makes the code look real nice. keeps it working too. problem right now is i need to continue making the arrays i am making with function names..

those arrays are then combined with regular expressions of numerous types of syntax and then used in if/elsif/else statements in a loop. the main look gets the file line by line and the inner loop evaluates each line until the line is out of characters.

basically.. the process of making it required me to run the script a zillion times. i would then open up the file and look where the script messed up. add that function into an array or make a new regex and then run the script again. it's very annoying.. but i want to finish this!!!

Smile i have to study for a calc test now.. so umm.. i'll finish tommorrow. would people want this script? it'd be more of a "bugware" than a script.. like.. find a bug.. fix it and tell everyone.

--
jsu
Quote Reply
Re: [Seto Kaiba] Formatting In reply to
You tried Acme::Bleach ;-)

<!-- Backup your code first before you accidentaly delete anything -->

- wil
Quote Reply
Re: [Wil] Formatting In reply to
OH wow.. But that's not even what I'm going for at all.

That just like.. compresses into a bunch of white spaces. Very cool, but I'm trying to make the code's formatting clean, easy to read. The way people would want it.

don't you hate it when people do something like..

if($booger eq 'boogie'){}else {

print "No boogers!\n";







}

but not just that.. I'm also reformatting the code so it's tabbed correctly and made easier to read/mod.

Like how all GT code is. As a matter of fact, I want to make it so that if I ran GT code through it.. practically nothing would happen. But when I run some random off-the-street bum's code.. I'll get GT style code.

I'm got close to finishing.. the 50kb script i was reformatting was about 2/3s of the way there.. but of course.. every other script will entail a new type of formatting required to be added to the regex.

BTW. I'm still up studying for calculus.. and not doing perl.

--
jsu
Quote Reply
Re: [Seto Kaiba] Formatting In reply to
>>
it's formatting a 50kb perl script file in about 16 seconds.
<<

That sounds a bit long to me. I wrote my own implementation of Data::Dumper which formats perl code (obviously not to the extent of a full script, just references, but it shouldn't be too hard. Not that it's easy but ....hmm I may have a play at that later on.

Last edited by:

Paul: Aug 1, 2002, 2:39 AM
Quote Reply
Re: [Paul] Formatting In reply to
There is a module that does this on CPAN, but I can't for the life of me remember it's name.

- wil
Quote Reply
Re: [Paul] Formatting In reply to
ya.. it is quite long.. but i don't care how long it takes.. i just want clean code. my method saves #comments also.. so it doesn't truncate everything.. if it did.. it would ruin alot of print qq~~;s also..

so that's why i made the script search for patterns in lines, until the line runs out, line after line. i thought that would be the best method.. rather than trying to doing some magic regex to the whole entire thing.

the only thing i've got to fix right now has to do with prints and stuff like that.. cause there are occasions where

print "blahlaskjdfjasdfajslfkjasfadslkfj\"lalallalalalla\"allalalalallala\"lalallala"; occur. and my original regex cut it off at the second quote and started a new line with the other junk on the next line. since it couldn't identify what the heck lalalalla was.. it decided that it was a continuation of the previous line.. and simply added it in.. but there was that newline.. so ya.. not a good regex.. but now i'm switching it over so it'll figure out the container form used.. then figure out where it would end by doing something like.. [^\\]"\)?;

understand? yes / no? well.. its very complicated.. and that's why.. speed doesn't matter to me on this one. also.. i don't want to make multiple regexes for the same things.. i want to make a single regex that will be able to make multiple functions and then reformat it.. using a bunch of split /,/, $params to split up the parameters in a function and then clean them up. yes? alot of work by the cpu.

--
jsu
Quote Reply
Re: [Seto Kaiba] Formatting In reply to
Hmm this isn't actually as easy as I thought.
Quote Reply
Re: [Paul] Formatting In reply to
Yes. lol.

Don't spend so much time at it. I'm pretty close to complete. Once it completes reformatting an entire script without errors.. I'll start working on efficiency.

--
jsu