By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

Problem using "open FILEPT, "zcat $filename|"" many times

P: 1
Hi,
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
  1. use Cwd;
  2. my $path=cwd();
  3.  
  4. sub proc{
  5.     my ($file) = @_;
  6.  
  7.     # (...)
  8.  
  9.     $pathC = $path . "/$file";
  10.     open INPUT, "zcat $pathC|" or trataErro($cpath);
  11.         while($line = <INPUT> ){
  12.             eval($line);
  13.  
  14.             # (...)
  15.         }
  16.     close INPUT;
  17. }
  18.  
  19. sub init{
  20.  
  21.     (...) #Initializing @lista
  22.  
  23.     for my $fileName (@lista){
  24.         proc($fileName);
  25.     }
  26. }
  27.  
  28. init;
  29.  
  30. #------------------------------------------------------------------
  31. sub trataErro{
  32.     my ($path) = @_;
  33.     open(STDIN, "-"); #Opens standard INPUT
  34.     print "\n!!ATENTION:\n\ttrataFile: Could not open file $cpath\n";
  35.     print "Check the problem with the file and type GO to continue\n";
  36.     while($line = <STDIN>){
  37.  
  38.         if ($line =~ m/GO/){
  39.             open INPUT, "$cpath" or trataErro($path);
  40.             close STDIN;
  41.             last;
  42.         } else {
  43.             print "Check the problem with the file and type GO to continue\n";
  44.         }
  45.     }
  46. }
  47.  
Jul 23 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.