I'm new to this forum and to Perl language but I would like to ask for your help.
I'm working in Linux and the files I need to process are in the format “file.gz”.
I created a script which should decompress, open and then delete nearly 400 files. To do so I use "open FILEPT, "zcat $filename|"".
In the beginning the script works fine, but after about 300 files processed I get an error on Open function:
“proc: Could not open file /home/Logs/backup/file.1183204803”.
I changed my script so I could continuing processing but the solution I found is not acceptable. So at the moment , when I get the Open error message, if I open a new shell and do : “zcat file.1183204803.gz > file.1183204803” and then type GO in the shell running my perl script, my script will continue execution normally until it needs to zcat and open another file when it will behave exactly the same way.
If I keep doing that I will get the expected result, but is unacceptable do all this manual work for 100 files!!
Do anyone knows why this happens and how to correct it?
Any help would be appreciated.
Thanks in advanced.
Here's, what I think to be, the relevant part of my script:
(Note: Function trataErro is at the bottom since it is not very relevant. I submitted it anyway, in case you wish to look at it.)
Expand|Select|Wrap|Line Numbers
- use Cwd;
- my $path=cwd();
- sub proc{
- my ($file) = @_;
- # (...)
- $pathC = $path . "/$file";
- open INPUT, "zcat $pathC|" or trataErro($cpath);
- while($line = <INPUT> ){
- eval($line);
- # (...)
- }
- close INPUT;
- }
- sub init{
- (...) #Initializing @lista
- for my $fileName (@lista){
- proc($fileName);
- }
- }
- init;
- #------------------------------------------------------------------
- sub trataErro{
- my ($path) = @_;
- open(STDIN, "-"); #Opens standard INPUT
- print "\n!!ATENTION:\n\ttrataFile: Could not open file $cpath\n";
- print "Check the problem with the file and type GO to continue\n";
- while($line = <STDIN>){
- if ($line =~ m/GO/){
- open INPUT, "$cpath" or trataErro($path);
- close STDIN;
- last;
- } else {
- print "Check the problem with the file and type GO to continue\n";
- }
- }
- }