perl pra wrote:
hi Mihir Kamdar,
Please the following highlighted.
I have tested it. this excatly does what you need.
configure the parent_path,child_path and out_path to your corresponding
paths.
_____________________ BEGIN
use strict;
use File::Path;
use File::Copy;
use warnings;
my $parent_path="C:/parent";
my $child_path="C:/child";
my $out_path="C:/output";
my @parent_files=<$parent_path/*>;
######### THIS SECTION ACTS AS the Touch Command Check the Files in Parent
Directory and Created the zero bye files in the Child directory#############
foreach my $file (@parent_files)
{
my @arr=$file=~ /(\w+\.\w+)$/;
Why are you doing this? What if the file name contains characters that don't
match \w? You should use File::Basename::basename to extract the file name
from the path or use opendir/readdir so that you don't have to separate the
file name from the path.
if (-f "$child_path/$arr[0]" )
{
}
else
{
open my $W_H, '>', "$child_path/$arr[0]" || die "Could not Create
the file $child_path/$arr[0]\n";
Because of the high precedence of the '||' operator the die() will *never*
execute! You need to either use parentheses:
open( my $W_H, '>', "$child_path/$arr[0]" ) || die "Could not
Create the file '$child_path/$arr[0]' $!";
or use the low precedence 'or' operator:
open my $W_H, '>', "$child_path/$arr[0]" or die "Could not Create
the file '$child_path/$arr[0]' $!";
close $W_H;
}
}
######################################################################################################################################
############################## this section Checks the files in the child
directory, Takes the same file from the parent directory removes duplicates
from the file and creates the file in output directory
#####################################################################################3
my @child_files=<$child_path/*>;
foreach my $file (@child_files)
{
my @arr=$file=~ /(\w+\.\w+)$/;
See above.
my %uniques;
open my $R_H, '<', "$parent_path/$arr[0]";
You should *always* verify that the file opened correctly.
my @file_content=<$R_H>;
close $R_H;
foreach my $line (@file_content) { $uniques{$line}++; }
open my $W_H, '>', "$out_path/$arr[0]";
You should *always* verify that the file opened correctly.
for(keys(%uniques)) { print $W_H "$_\n"; }
close $W_H;
}
######################################################################################################################################
_________________________________ END
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/