Problem using Archive::Zip !

E

Ej

This does not work, Why?

@fla=('/root/name/dir1','/root/name/dir2');

foreach $ia (@fla){

print "adding $ia<br>";
$status=$zip->addTree( "$ia","$ia" );
$status->desiredCompressionMethod( COMPRESSION_DEFLATED );
$status->desiredCompressionLevel(5);

}

I get this message:
Can't call method "desiredCompressionMethod" without a package or object
reference at zp1.pl line 38.


however, this does work,

foreach $ia (@fla){

print "adding $ia<br>";
$status=$zip->addTree( "$ia","$ia" );
}

how can I fix the first code?

Thank You.
 
J

J. Gleixner

Ej said:
This does not work, Why?

@fla=('/root/name/dir1','/root/name/dir2');

foreach $ia (@fla){

print "adding $ia<br>";
$status=$zip->addTree( "$ia","$ia" );
$status->desiredCompressionMethod( COMPRESSION_DEFLATED );
$status->desiredCompressionLevel(5);

}

I get this message:
Can't call method "desiredCompressionMethod" without a package or object
reference at zp1.pl line 38.


however, this does work,

foreach $ia (@fla){

print "adding $ia<br>";
$status=$zip->addTree( "$ia","$ia" );
}

how can I fix the first code?

What's $status???.. hint.. it's not an object, which is what the error
is telling you. It's what addTree returns, which, according to the
documentation, is "AZ_OK". Use the Archive::Zip object, which, since you
didn't show it's creation in your posted code, I assume is $zip.

$zip->desiredCompressionMethod(...);
 
E

Ej

What's $status???.. hint.. it's not an object, which is what the error
is telling you. It's what addTree returns, which, according to the
documentation, is "AZ_OK". Use the Archive::Zip object, which, since
you didn't show it's creation in your posted code, I assume is $zip.

$zip->desiredCompressionMethod(...);

Hi, I tried that as well as other things but get the same error,
can someone PLEASE post an example code using $zip->addTree('','')
that works or maybe this is a bug in Archive::Zip, that does not work.

thank you.
 
B

Bill

can someone PLEASE post an example code using $zip->addTree('','')
that works or maybe this is a bug in Archive::Zip, that does not work.

thank you.

Something like this, maybe?

use strict;
use Carp;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use Archive::Zip::Tree;

my $rootdir = '/tmp';
my $archname = 'archived.zip';
my $destfile = $rootdir . '/' . $archname;

my $bytesdone = 0;
my $progress = sub {
my $f = $_;
return 0 unless(-f $f and lc $f ne $archname);
$bytesdone += -s $f;
print $bytesdone, " total bytes archived ",
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
return 1;
};

my $zip = new Archive::Zip or carp("Cannot make zip object: $!");
print "\nZipping directory $rootdir as $destfile\n";
$zip->addTree($rootdir, undef, $progress) == AZ_OK
or die "No good adding tree $rootdir";
my @members = $zip->members;
my $member = $members[0];
$member->desiredCompressionMethod(COMPRESSION_DEFLATED);
$member->desiredCompressionLevel(5);
$zip->writeToFileNamed($destfile) == AZ_OK or
carp ("Write error for zip object to $destfile: $!");
print "\nDone.\n";

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
V

Vertica Garg

Try using:

my @members = $zip->memberNames();

my $member = $zip->memberNamed($members[0]);

$member->desiredCompressionMethod(COMPRESSION_DEFLATED );

$member->desiredCompressionLevel(5);

Regards,

Vertica

Bill said:
Ej <[email protected]_NOSPAM> wrote in message
can someone PLEASE post an example code using $zip->addTree('','')
that works or maybe this is a bug in Archive::Zip, that does not work.

thank you.

Something like this, maybe?

use strict;
use Carp;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use Archive::Zip::Tree;

my $rootdir = '/tmp';
my $archname = 'archived.zip';
my $destfile = $rootdir . '/' . $archname;

my $bytesdone = 0;
my $progress = sub {
my $f = $_;
return 0 unless(-f $f and lc $f ne $archname);
$bytesdone += -s $f;
print $bytesdone, " total bytes archived ",
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\
b";
return 1;
};

my $zip = new Archive::Zip or carp("Cannot make zip object: $!");
print "\nZipping directory $rootdir as $destfile\n";
$zip->addTree($rootdir, undef, $progress) == AZ_OK
or die "No good adding tree $rootdir";
my @members = $zip->members;
my $member = $members[0];
$member->desiredCompressionMethod(COMPRESSION_DEFLATED);
$member->desiredCompressionLevel(5);
$zip->writeToFileNamed($destfile) == AZ_OK or
carp ("Write error for zip object to $destfile: $!");
print "\nDone.\n";

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top