#!/usr/bin/perl -w ########### zip.pl ################ # Testing for modul Active::zip # Unpack given ZIP files in the same directory use lib './'; use strict; use Carp; use Encode; use Encode::Guess; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use utf8; use open ':utf8'; binmode STDOUT,':utf8'; my $zip = Archive::Zip->new(); my @encodings = qw(ascii cp850); my $m = ''; my $n = ''; my $charset = ''; die 'read error: ',$ARGV[0] unless $zip->read( $ARGV[0] ) == AZ_OK; foreach $m ($zip->members()) { print "member filename: ",$m->fileName(),"\n"; print "fileAttributeFormat: ", $m->fileAttributeFormat(),"\n"; $n = $m->fileName(); print "Try to guess encoding\n"; $charset = guess_encoding($n, @encodings); #no charset found unless (ref $charset) { print "No charset found: $charset\n"; print "Using member filename like it is: $n\n"; $zip->extractMember($m); next; } #charset found $charset = $charset->name; print "Guessed charset: ",$charset,"\n"; print "Archive given member filename is $n.\n"; $n = decode($charset,$n); $m->extractToFileNamed($n) ; print "Decoded to $n\n"; print "----------------\n"; } print 'done.';