PayPal is the easiest way to receive money online. Get one now or Click here to sign up. Sign up for PayPal and start accepting credit card payments instantly.

Simple Perl Tidy.

This code below will tidy your perl code.

use File::Copy;
opendir (DIR , Win32::GetCwd());
my @DIR = readdir(DIR);
closedir DIR;

my $tabValues = ' ';
my $FileToClean ='myperlfile.pl';
#foreach(@DIR)
{
# my $FileToClean ='myperlfile.pl';
#$FileToClean =$_;
# next if ($FileToClean =~ /\.bak$/gi);
copy ($FileToClean,"$FileToClean.bak");
open(FILE ,"$FileToClean");
my $templine;
my $tab;
while(my $line = )
{
$line =&trim($line);
#print $line."\r\n";
if ($line =~ /.*TOVALIDDATE.*/gi)
{
print "test\n";
}
if ($line ne "")
{
if ($line=~ /.*\(.*\)\{.*\}/gi)
{
$templine .= $tab.$line."\r\n";
next;
}
if ($line=~ /(^(while|if|else|elsif|foreach).*\(.*\).*)(\{.*)/gi)
{

$templine .= $tab.$1."\r\n";
$templine .= $tab.$3."\r\n";
$tab .= $tabValues;
next;
}
if($line=~ /^#/gi)
{
$templine .= $tab.$line."\r\n";
next;
}
if($line=~ /^{/gi || $line=~ /^(while|if|else|elsif|foreach).*{$/gi)
{
$templine .= $tab.$line."\r\n";
$tab .= $tabValues;
next;
}
if($line=~ /^}/gi || $line=~ /^}.*(while|if|else|elsif|foreach).*/gi)
{
$tab =~ s/$tabValues//;
if($line=~ /^{/gi || $line=~ /.*(while|if|else|elsif|foreach).*{/gi)
{
$tab .= $tabValues;
}
$templine .= $tab.$line."\r\n";
next;
}
if($line=~ /}$/gi || $line=~ /.*(while|if|else|elsif|foreach).*}$/gi)
{
$tab =~ s/$tabValues//;
#$line =~ s/}/$tab}/;
$templine .= $tab.$line."\r\n";
next;
}
if($line=~ /^sub .*/gi)
{
$tab="";
$templine .= $tab.$line."\r\n";
my $aaa= trim($line);
if($aaa=~ /^sub .*{$/gi)
{
$tab=$tabValues;
}
next;
}

$templine .= $tab.$line."\r\n";
}
}
close FILE;
open(FILEOUT,">$FileToClean");
print FILEOUT $templine;
close FILEOUT;
}
exit;
sub trim
{
my $str = shift;
$str =~ s/^\s+//;
$str =~ s/\s+$//;
return $str;
}

No comments:

WebProNews Feed

eWeek - RSS Feeds

HowtoForge - Howtos and Tutorials

The Register

PayPal is the easiest way to receive money online. Get one now or Click here to sign up. Sign up for PayPal and start accepting credit card payments instantly.