Mihir Kamdar wrote:
As soon as the data file is updated completely, the tag file is touched with
the same name in the child directory.
This process is automatic. No manual touching of tag files.
As per my requirement, in my code, I am trying to open the child directory,
read the tag name, open the parent directory,and corresponding to that tag,
pick up the data file, process it and write the output to another directory.
After processing, both the tag file as well as data file needs to be
deleted. We should only have the output file in the output directory.
There is no possibility of updating or appending any data file in the parent
directory once a tag file is created for it in the child directory.
The files keep on coming. As soon as the new files come, they need to get
processed, outputted into the output directory and the tag file as well as
the processed file should be removed.
So our perl script should run infinitely.
At one time, we need to process only one file.
Hope this helps and u r able to help me out.
Just a rough version:
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Copy;
my $TagDir = 'TBD';
my $FilesDir = 'TBD';
my $TmpDir = 'TBD';
my $OutputDir = 'TBD';
for(;;) {
my @tag_files = glob( "$TagDir/*" );
my %files = map { basename( $_ ), $FilesDir . basname( $_ ) } @tag_files;
for my $file ( keys %files ){
move( $files{$file}, "$TmpDir/$file" ) or die "cannot move file $file: $!";
$files{$file} = "$TmpDir/$file";
}
for my $file ( keys %files ){
my $output_file = "$OutputDir/$file";
open my $in_fh, '<', $files{$file} or die "cannot open $file: $!";
open my $out_fh, '>', $output_file or die "cannot open $output_file: $!";
while( <$in_fh> ){
# process file
# print output
}
close $in_fh;
close $out_fh;
unlink $files{$file}, "$TagDir/$file";
}
sleep 4;
}
__END__
--
Just my 0.00000002 million dollars worth,
Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/