RICHARD FERNANDEZ wrote: > Hi Folks, Hello,
> I have a job that takes in an encrypted file and decrypts it using > Crypt::GPG. > > <code> > for my $encrypted_file (@files) { > > open(CIPHERTXT, $encrypted_file) or croak "Can't open > encrypted_file: $encrypted_file\n"; You should include the $! (or perhaps the $^E) variable in your error message so you will know why it croaked. You probably need to binmode() the filehandle. perldoc -f binmode > my @ciphertxt = <CIPHERTXT>; > > my($cleartxt, $signature) = $gpg -> decrypt([EMAIL PROTECTED]); > > # File names must have a ".extension" on them if they're > encrypted > # we will strip off the last "dot" and everything after it to > name the > # clear text file > my $filename = (split /\.\w+$/, $encrypted_file)[0]; You probably want to use substitution in instead of split. ( my $filename = $encrypted_file ) =~ s/\.\w+$//; > open(CLEARTXT, ">", "$filename") or croak "Can't write to perldoc -q quoting > $filename: $!\n"; > print CLEARTXT $cleartxt or croak "Can't print cleartext: > $!\n"; > close CLEARTXT or croak "Can't close <CLEARTXT>?\n"; > > push @processed_files, $filename or croak "Can't create list of perldoc -f push push ARRAY,LIST Treats ARRAY as a stack, and pushes the values of LIST onto the end of ARRAY. The length of ARRAY increases by the length of LIST. Has the same effect as for $value (LIST) { $ARRAY[++$#ARRAY] = $value; } but is more efficient. Returns the new number of elements in the array. The only way that your expression will croak is if @processed_files is empty and you push an empty list on to it. $ perl -le' push @x, $y or die "Push error" ' $ perl -le' push @x, () or die "Push error" ' Push error at -e line 1. In other words, your expreesion will *never* croak. > decrypted files!\n"; > } > </code> > > Mostly, this works as I expect, but once in a blue moon we get a > ciphertext that produces a 0 byte cleartext file when run > through the above code. When I decrypt the file manually (gpg --decrypt > <filename> > clear.txt ) I get a good (readable) cleartext file. You probably need to use binmode on your filehandles. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>