mikejones has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I am wondering what to do if for example Compress::Zlib is not installed while using LogFile::Rotate. I searched through the archives and came up empty.

For example in this code I originally tried to use both Gzip options, but Perl would YAK at me when it failed on one.

< snip > sub logroll { my $logs = new Logfile::Rotate( File => $log, Count => 15, Gzip => 'lib', Gzip => '/usr/bin/gzip', Dir => $logdir, Flock => 'yes', Persist => 'yes' ) ; $logs->rotate() ; }

Can I use an or statement? Please help with this code so that if lib fails it will try gzip and not YAK at me...don't like to be YAKed at! : )

Replies are listed 'Best First'.
Re: what to do if module is not installed, YIKES!
by runrig (Abbot) on May 06, 2008 at 19:46 UTC
    According to the docs, Logfile::Rotate automatically uses Compress::Zlib if it is available, and command line gzip if not. You don't need to specify the Gzip argument if you don't know for sure which option you want to use.
Re: what to do if module is not installed, YIKES!
by moritz (Cardinal) on May 06, 2008 at 19:05 UTC
    What about this one?
    my $gzip = '/usr/bin/gzip'; if (!-x $gzip){ $gzip = 'lib'; } my $lgos = new Logfile::Rotate( Gzip => $gzip, ... );
      yes that will work, but was thinking some kind of 'or' code within the sub. thank you however!