472,143 Members | 1,113 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

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

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();
  4. sub proc{
  5.     my ($file) = @_;
  7.     # (...)
  9.     $pathC = $path . "/$file";
  10.     open INPUT, "zcat $pathC|" or trataErro($cpath);
  11.         while($line = <INPUT> ){
  12.             eval($line);
  14.             # (...)
  15.         }
  16.     close INPUT;
  17. }
  19. sub init{
  21.     (...) #Initializing @lista
  23.     for my $fileName (@lista){
  24.         proc($fileName);
  25.     }
  26. }
  28. init;
  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>){
  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. }
Jul 23 '07 #1
0 2515

Post your reply

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

Similar topics

1 post views Thread by Sameh Abdelatef | last post: by
12 posts views Thread by kimiraikkonen | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.