use strict;
use Getopt::Long;
use English;
use CWD;
use Tie::File;
use warnings;
my $HomeDir="C:\\DDL";
my $ConfigFile = $HomeDir . "\\" . "Conf.txt";
my $RunFolder = $HomeDir . "\\Ods";
my $OutFile = $HomeDir . "\\" . "OutPut.csv";
my $dir;
my $TempDir = "C:\\DDL\\Temp";
my %ConfigVar;
my $ParentName = 'Parent Name';
my $ChildName = 'Child Name';
my $SNO= 'S.NO';
my @FileArray;
my $char = '(';
##################################################################
# Name:ReadConfigFile
# Description:Reading config files
# Inputs: $1=
# Return Code 0
####################################################################
sub ReadConfigFile {
my @ConfigArray;
# Open the file.
open(INFILE, $ConfigFile) or die "Cannot open $ConfigFile: $!.\n";
while(my $l = <INFILE>)
{
chomp($l);
@ConfigArray = split(/=/, $l);
$ConfigVar{$ConfigArray[0]} = $ConfigArray[1];
}
close INFILE;
}
##################################################################
# Name:GetFilesCount
# Description: Counting the number of files in the folder
# Inputs: $1=
# Return Code 0
####################################################################
sub GetFilesCount
{
my @files = <$dir/*>;
my $count = @files;
print "Total Number of files present in Folder ".$dir." = ".$count."\n\n";
}
##################################################################
# Name:CountNoFileinFolders
# Description: Counting the number of files in the folder
# Inputs: $1=
# Return Code 0
####################################################################
sub GetFilesName
{
my $fileName='';
my $count;
foreach my $fp (glob("$dir/*"))
{ # looping file one by one
$count = 0;
open my $fh, "<", $fp or die "can't read open '$fp': $OS_ERROR";
$fileName = $fp;
while (<$fh>) # Reading file
{
chomp($_);
if ($_ =~ m/(^|(\s)+)create procedure(\s)+/i or $_ =~ m/(^|(\s)+)replace procedure(\s)+/i)
{
$count++;
}
}
if($count = 1)
{
print $fileName."\n";
CreateTempFiles($fileName);
}
if($count > 1)
{
CreateTempFiles($fileName);
}
close $fh or die "can't read close '$fp': $OS_ERROR";
}
}
###########CreateTempFiles#######################################################
# Name:CreateTempFiles
# Description: For a single file it will break files in parts
# Inputs: $1=
# Return Code 0
####################################################################
sub CreateTempFiles
{
my $ProcName;
my $linenumbers = 0;
my $Lastline = 0;
my $LL;
my $LLN;
my $files ;
open my $fh, "<", $_[0] or die "can't read open '$_[0]': $OS_ERROR";
while (<$fh>) # Reading file
{
chomp($_);
if ($_ =~ m/(^|(\s)+)create procedure(\s)+/i or $_ =~ m/(^|(\s)+)replace procedure(\s)+/i)
{
my $ObjectName = $_;
$ObjectName =~ /\./g;
$ObjectName = $';
$ObjectName =~ s/^(\s|\t)+//g;
$ObjectName =~ /(\s|\(|$)/g;
$ObjectName = $`;
$ObjectName =~ s/(\.|\"|\s|\()//g;
$files = "${TempDir}\\${ObjectName}.sql";
open(OUTFILE, ">", $files) or die "Cann't open $files : $!.\n";
}
print OUTFILE $_."\n";
}
close $fh or die "can't read close '$_[0]': $OS_ERROR";
}
##################################################################
# Name:ReadFile
# Description: Counting the number of files in the folder
# Inputs: $1=
# Return Code 0
####################################################################
sub ReadFileX
{
my $CallCount = 0;
$ParentName = "";
foreach my $fp (glob("$TempDir/*"))
{ # looping file one by one
open my $fh, "<", $fp or die "can't read open '$fp': $OS_ERROR";
while (<$fh>) # Reading file
{ print "test1\n";
chomp($fh);
print "$fh \n";
if ($fh =~ m/(^|(\s)+)create(\s)+/i or $fh =~ m/(^|(\s)+)replace(\s)+/i)
{
$ParentName = $fh;
}
if ($fh =~ m/(^|(\s)+)call(\s)+/i)
{
$CallCount++;
}
}
close $fh or die "can't read close '$fp': $OS_ERROR";
print $CallCount."\n";
if ($CallCount == 0)
{
print $CallCount." Call couint is zero \n";
#GenExcel($ParentName,"Parent Do not have any Child");
}
if ($CallCount > 0)
{
open my $fq, "<", $fp or die "can't read open '$fp': $OS_ERROR";
while (<$fq>) # Reading file
{
chomp($_);
if ($_ =~ m/(^|(\s)+)create(\s)+/i or $_ =~ m/(^|(\s)+)replace(\s)+/i)
{
GenExcel($ParentName,$_);
}
}
close $fq or die "can't read close '$fp': $OS_ERROR";
}
}
}
sub ReadFile
{
print "I have reached in new Read files \n ";
foreach my $fF (glob("$TempDir/*"))
{ # looping file one by one
open my $Ph, "<", $fF or die "can't read open '$fF': $OS_ERROR";
while (<$Ph>) # Reading file
{
chomp($_);
print $_."\n";
}
}
}
sub GenExcel
{
if ($_[0] eq 'Parent Name')
{
open(OUTFILE, ">>", $OutFile) or die "Cann't open $OutFile : $!.\n";
print OUTFILE "$_[0],$_[1]"."\n";
}else
{
if($_[1] eq "Parent Do not have any Child")
{
open(OUTFILE, ">>", $OutFile) or die "Can't open $OutFile : $!.\n";
print OUTFILE "$_[0],$_[1]"."\n";
}else
{
my $Cname = substr($_[1],0,index($_[1],$char));
$Cname = substr($Cname,4);
open(OUTFILE, ">>", $OutFile) or die "Can't open $OutFile : $!.\n";
print OUTFILE "$_[0],$Cname"."\n";
}
}
}
print "Start\n";
ReadConfigFile();
$dir = $ConfigVar{"PROCPATH"} ;
#$TempDir = $ConfigVar{"TempFile"} ;
$dir =~ s/ //ig;
#$TempDir =~ s/ //ig;
#GenExcel($ParentName,$ChildName);
GetFilesCount();
GetFilesName();
#ReadFile();
print"---------------------------------\n";
print"\n";
print "End\n";
---------
use strict;
use Getopt::Long;
use English;
use CWD;
use Tie::File;
use warnings;
my $ParName ='Parent Name';
my $char = '(';
my $TempDir = "C:\\DDL\\Temp";
my $HomeDir="C:\\DDL";
my $ConfigFile = $HomeDir . "\\" . "Conf.txt";
my $OutFile = $HomeDir . "\\" . "OutPut.csv";
sub GetFilesCount
{
my @files = <$TempDir/*>;
my $count = @files;
print "Total Number of files present in Folder ".$TempDir." = ".$count."\n\n";
}
##################################################################
# Name:ReadFile
# Description: Counting the number of files in the folder
# Inputs: $1=
# Return Code 0
####################################################################
sub ReadFile
{
my $CallCount = 0;
my $ParentName;
foreach my $fp (glob("$TempDir/*"))
{ # looping file one by one
open my $fh, "<", $fp or die "can't read open '$fp': $OS_ERROR";
while (<$fh>) # Reading file
{
chomp($_);
if ($_ =~ m/(^|(\s)+)create(\s)+/i or $_ =~ m/(^|(\s)+)replace(\s)+/i)
{
$ParentName = $_;
}
if ($_ =~ m/(^|(\s)+)call(\s)+/i)
{
$CallCount++;
}
}
close $fh or die "can't read close '$fp': $OS_ERROR";
if ($CallCount == 0)
{
GenExcel($ParentName,"Parent Do not have any Child");
}
if ($CallCount > 0)
{
#chomp($fp);
open my $fq, "<", $fp or die "can't read open '$fp': $OS_ERROR";
while (<$fq>) # Reading file
{
chomp($_);
if($_ =~ m/(^|(\s)+)call(\s)+/i)
{
GenExcel($ParentName,$_);
}
}
close $fq or die "can't read close '$fp': $OS_ERROR";
}
}
}
sub GenExcel
{
if ($_[0] eq 'Parent Name')
{
open(OUTFILE, ">>", $OutFile) or die "Cann't open $OutFile : $!.\n";
print OUTFILE "$_[0],$_[1]"."\n";
}else
{
if($_[1] eq "Parent Do not have any Child")
{
open(OUTFILE, ">>", $OutFile) or die "Can't open $OutFile : $!.\n";
print OUTFILE "$_[0],$_[1]"."\n";
}else
{
my $Pname = substr($_[0],0,index($_[0],$char));
$Pname =~ s/^\s+//;
my $Cname = substr($_[1],0,index($_[1],$char));
$Cname =~ s/^\s+//;
open(OUTFILE, ">>", $OutFile) or die "Can't open $OutFile : $!.\n";
print OUTFILE "$Pname,$Cname"."\n";
}
}
}
GenExcel($ParName,'Child Name');
GetFilesCount();
ReadFile();