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+)$/; 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"; 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+)$/; my %uniques; open my $R_H, '<', "$parent_path/$arr[0]"; my @file_content=<$R_H>; close $R_H; foreach my $line (@file_content) { $uniques{$line}++; } open my $W_H, '>', "$out_path/$arr[0]"; for(keys(%uniques)) { print $W_H "$_\n"; } close $W_H; } ###################################################################################################################################### _________________________________ END Regards, Siva On 8/2/07, Mihir Kamdar <[EMAIL PROTECTED]> wrote: > > Hi, > > I have a requirement. There are files in the parent directory and they are > touched in the child directory. So in child directory there are 0 byte > files > having the same name as the ones in the parent directory. I need to read > files in the child directory, and for each file present in the child > directory, I need to take that file from the parent directory, process > that > file(remove duplicate lines from that file), and then write the output for > each of the input files in the output directory. > > I have written the code as below but it gives 0 byte files as output. > Please > suggest what is wrong with the below code. > I have a fear that instead of processing files from parent directory, it > is > processing files from the child directory. > > I am a newbie at perl. So i might have made silly mistakes. Request you to > correct them. > > > > #!/usr/bin/perl > > my $child_path = > > '/home/user71/RangerDatasource/Customization/TelekomMalaysia/Scripts/Tests/cprogs/files/child' > ; > my $parent_path = > > '/home/user71/RangerDatasource/Customization/TelekomMalaysia/Scripts/Tests/cprogs/files' > ; > my $write_path = > > '/home/user71/RangerDatasource/Customization/TelekomMalaysia/Scripts/Tests/cprogs/files/output' > ; > my $line; > my %hash; > my @file; > my $key ; > my $value ; > > while () { > > opendir my $dh, $child_path or die $!; > > while (my $file = readdir $dh) { > > my $fname = "$child_path/$file"; > next unless -f $fname; > unless (exists $times{$file}){ > > opendir my $dh1,$parent_path or die $!; > > while (my $file = readdir $dh1) { > > while ($line=readline($file)) > { > my @cdr=split (/,/, $line) ; > > $hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line; #Add some more cdr key > fields > if u want. > } > close $file ; > } > closedir $dh1 ; > > open (my $OUT_FILE,">","$write_path/$file.out") or die $!; > while (($key, $value) = each %hash) > { > print $OUT_FILE $value; > } > close $OUT_FILE; > } > unlink("$parent_path/$file") ; > unlink("$child_path/$file") ; > > > } > closedir $dh; > } >