On 8/2/07, Mihir Kamdar <[EMAIL PROTECTED]> wrote:
>
>
>
> 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;
> > }
> >
> >
> a little correction in the above code:
> #!/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 ;
> my %times ;
> 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;
> }
>
> Hi,
No replies from anybody. Can anybody plz help me with the above code?
Thanks,
Mihir