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

Guys, having a lot of trouble trying to import. Could really use some help. I am getting String found where operator expected at ./backup_db.pl line 1512, near "gzip "${FileName}"" (Do you need to predeclare gzip?) Am I doing this wrong?

if (eval { require IO::Compress::Gzip } ) { IO::Compress::Gzip->import ( qw (gzip $GzipError) ); $status = gzip "${FileName}" => "${FileName}.gz" or die "gzip failed: +$GzipError\n";

Replies are listed 'Best First'.
Re: Help with import of module
by choroba (Cardinal) on Sep 21, 2015 at 16:18 UTC
    If you want to use subroutine names as barewords, you have to declare them in the compilation phase, i.e. through use or in a BEGIN block. Otherwise, just add the parentheses around the subroutine's arguments.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      In case someone googles this, here is how I fixed it
      if (eval { require IO::Compress::Gzip } ) { use subs qw (gzip); use vars qw ($GzipError); IO::Compress::Gzip -> import ( qw (gzip $GzipError) ); $status = gzip "${FileName}" => "${FileName}.gz" or _error "gzip f +ailed: $GzipError\n"; } else { system qq[gzip -c ${FileName} > ${FileName}.gz]; }