D
Deepu
Hi All,
If i have a files located in different directories with contents like:
File_A:
ABCD : 1
DECF : 0
DREF : 1
DSER : 0
QWSA : 0
File_B:
ABCD : 1
DECF : 1
DREF : 0
DSER : 0
QWSA : 0
File_C:
ABCD : 1
DECF : 0
DREF : 1
DSER : 0
QWSA : 1
How can i generate a output file:
File_Output:
ABCD : 1
DECF : 1
DREF : 1
DSER : 0
QWSA : 1
In addition to this FileOutput should contain:
Num of Files: 3
Num of Elements: 5
Num of Hits : 4 (Elements with 1 after comparing all 3 files)
I have the code like below but would like to know how i get the Num of
Hits after comparing all 3 files.
use strict;
use Getopt::Long;
use IO::Handle;
use vars qw($opt_help $opt_dir $opt_debug);
&GetOptions("help|h" => \$opt_help,
"dir|d=s" => \$opt_dir,
"debug" => \$opt_debug
);
my $Dir = "$opt_dir";
my $num_of_files = 0;
my $num_of_elements = 0;
my $num_of_hits = 0;
my %num_of_elements = ();
opendir (DIR, $Dir) || die "Can't open $Dir - $!\n";
foreach my $tempdir (readdir DIR)
{
if (-d "$Dir/$tempdir")
{
$num_of_files = $num_of_files + 1;
opendir (SUB, "$Dir"."/$tempdir" ) || die "Can't open
$tempdir - $!\n";
my $Name = $tempdir;
my $elementFile = "$Dir/$tempdir/"."File_$Name";
open (FH, "$elementFile") || die "Can't open $elementFile -$!
\n";
while (<FH>)
{
if (/(\S+)\s+\:\s+(\d+)/)
{
$num_of_elements{$1}++;
}
}
close (FH);
closedir (SUB);
}
}
closedir (DIR);
foreach my $element (keys %num_of_elements)
{
$num_of_elements = $num_of_elements + 1;
}
print ("\n________________________________________\n");
print ("Num of Files: $num_of_files \n");
print ("Num of Elements: $num_of_elements \n");
print ("Num of Hits: $num_of_hits \n");
print ("________________________________________\n");
If i have a files located in different directories with contents like:
File_A:
ABCD : 1
DECF : 0
DREF : 1
DSER : 0
QWSA : 0
File_B:
ABCD : 1
DECF : 1
DREF : 0
DSER : 0
QWSA : 0
File_C:
ABCD : 1
DECF : 0
DREF : 1
DSER : 0
QWSA : 1
How can i generate a output file:
File_Output:
ABCD : 1
DECF : 1
DREF : 1
DSER : 0
QWSA : 1
In addition to this FileOutput should contain:
Num of Files: 3
Num of Elements: 5
Num of Hits : 4 (Elements with 1 after comparing all 3 files)
I have the code like below but would like to know how i get the Num of
Hits after comparing all 3 files.
use strict;
use Getopt::Long;
use IO::Handle;
use vars qw($opt_help $opt_dir $opt_debug);
&GetOptions("help|h" => \$opt_help,
"dir|d=s" => \$opt_dir,
"debug" => \$opt_debug
);
my $Dir = "$opt_dir";
my $num_of_files = 0;
my $num_of_elements = 0;
my $num_of_hits = 0;
my %num_of_elements = ();
opendir (DIR, $Dir) || die "Can't open $Dir - $!\n";
foreach my $tempdir (readdir DIR)
{
if (-d "$Dir/$tempdir")
{
$num_of_files = $num_of_files + 1;
opendir (SUB, "$Dir"."/$tempdir" ) || die "Can't open
$tempdir - $!\n";
my $Name = $tempdir;
my $elementFile = "$Dir/$tempdir/"."File_$Name";
open (FH, "$elementFile") || die "Can't open $elementFile -$!
\n";
while (<FH>)
{
if (/(\S+)\s+\:\s+(\d+)/)
{
$num_of_elements{$1}++;
}
}
close (FH);
closedir (SUB);
}
}
closedir (DIR);
foreach my $element (keys %num_of_elements)
{
$num_of_elements = $num_of_elements + 1;
}
print ("\n________________________________________\n");
print ("Num of Files: $num_of_files \n");
print ("Num of Elements: $num_of_elements \n");
print ("Num of Hits: $num_of_hits \n");
print ("________________________________________\n");