I am new to Perl, not a programmer. I inherited a script that works well but runs me out of space. Would like to add zipping of the files as the script rotates the logs. Any help pointing me in the right direction would be appreciated. Scipt is below in code tags I think?

I receive the following errors when I run with use strict and warnings. Have tried but canít seem to fix them.

This may look painful, but it actually helps you avoiding more difficult to detect mistakes, like typos in the name of variables.

Having said that, there is more to it than simply pre-declaring your lexical variables. The place where you do this declaration is also important. Often, Perl beginners declare all their variables at the beginning (at the very top of the program, as is often done in other languages). This is better than not declaring them, but this is often not optimal at all; usually, variables should be declared in the smallest scope possible. But it is a bit complicated to explain these things in details here in a forum.

Use of uninitialized value $file in hash element at ./logger-with-rotate.pl line 32. Use of uninitialized value $file in hash element at ./logger-with-rotate.pl line 33. sysseek() on closed filehandle $handles{...} at ./logger-with-rotate.pl line 33. Use of uninitialized value $filesz in numeric gt (>) at ./logger-with-rotate.pl line 36. Use of uninitialized value $file in hash element at ./logger-with-rotate.pl line 154. Use of uninitialized value $file in hash element at ./logger-with-rotate.pl line 166. syswrite() on closed filehandle $handles{...} at ./logger-with-rotate.pl line 166.

Hm, you should probably post your new code, removing out commented out code and giving the errors obtained after having removed commented out code. This will make it easier to find where the remaining errors are.

I haven't taken the time to examine you full code (I wait for a cleanout version), but my guess (without having tried to understand everything that you are doing at this point) is that you should probably change:

Code

if ($handles{$file}) { # ...

to something like:

Code

if (defined $handles{$file}) { # ...

The other "unitialized value" errors are probably similar.

The second point (again I haven't checked, I would prefer to look at cleaned code) is that you were probably not aware to open the file whose filehandle is $handle.

I agree with Laurent_R about needing to see your updated code so we can better help you.

The code you've posted so far has a number of problems and until we resolve those issues, I hesitate to make suggestions on the adding of the zip file code. Doing so at this point, IMO, would only serve to make the code more difficult to deal with.

One point I will make now is to somewhat disagree with Laurent_R's last suggestion on the conditional used to check $handles{$file}. Checking if it's defined in not sufficient. It could be defined, but still not be a filehandle that can be read from or written to.

You could use the ref() function to check/verify that it's a type GLOB (i.e. the function returns 'GLOB'). But that still doesn't tell you if it's an open filehandle. To test for that condition, you use the fileno() function.