in reply to Perl Archiving Process error

The error is pretty explicit. $newMember is undef.

You can either check that the $newMember is defined before calling a method on it: warn "Error while archiving file $fileName to $newName" and return unless defined $newMember
or catch the error with an eval eval { $newMember->desiredCompressionLevel($compressionLevel); 1; } or warn "Error for file $fileName, $newName : $@" and return;

eval will return the last instruction (here 1) if it executes correctly or undef if an error is raised. So with the idiom eval { THING; 1; } a true value will be returned on success.

eval { THING }; warn if $@;
does the same thing by checking the state of the variable $@.

Once you have found which file is a problem, you'll have to find out why newFromFile() returns undef in that case.

Replies are listed 'Best First'.
Re^2: Perl Archiving Process error
by choroba (Cardinal) on Jul 12, 2016 at 13:14 UTC
    > does the same thing

    Not always. See Bug in eval in pre-5.14.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      OK so the eval { BLOCK; 1 } or do { } idiom isn't just about finding the shortest or cutest way to write it. Thanks for the info :)