Problem using Archive::Zip !

Discussion in 'Perl Misc' started by Ej, Oct 23, 2003.

  1. Ej

    Ej Guest

    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.
    Ej, Oct 23, 2003
    #1
    1. Advertising

  2. Ej

    J. Gleixner Guest

    Ej wrote:
    > 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(...);
    J. Gleixner, Oct 23, 2003
    #2
    1. Advertising

  3. Ej

    Ej Guest

    "J. Gleixner" <> wrote in
    news:99Wlb.2251$:

    > Ej wrote:
    >> 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(...);
    >


    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.
    Ej, Oct 24, 2003
    #3
  4. Ej

    Bill Guest

    Ej <_NOSPAM> wrote in message news:<>...
    > "J. Gleixner" <> wrote in
    > news:99Wlb.2251$:
    > >> I get this message:
    > >> Can't call od "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" );
    > >> }
    > >>


    > 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";

    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Bill, Oct 25, 2003
    #4
  5. Ej

    Vertica Garg Guest

    Try using:

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

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

    $member->desiredCompressionMethod(COMPRESSION_DEFLATED );

    $member->desiredCompressionLevel(5);

    Regards,

    Vertica

    "Bill" <> wrote in message
    news:...
    > Ej <_NOSPAM> wrote in message

    news:<>...
    > > "J. Gleixner" <> wrote in
    > > news:99Wlb.2251$:
    > > >> I get this message:
    > > >> Can't call od "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" );
    > > >> }
    > > >>

    >
    > > 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";
    >
    > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Vertica Garg, Dec 17, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Graham Wood
    Replies:
    3
    Views:
    512
    A. Sinan Unur
    Jan 11, 2004
  2. Twig
    Replies:
    1
    Views:
    120
    A. Sinan Unur
    Jan 27, 2006
  3. MoshiachNow
    Replies:
    2
    Views:
    257
    Ilya Zakharevich
    Oct 4, 2006
  4. MoshiachNow

    Archive::Zip - zip file has "invalid" format

    MoshiachNow, Oct 5, 2006, in forum: Perl Misc
    Replies:
    1
    Views:
    151
  5. Bo Yang
    Replies:
    9
    Views:
    286
    -berlin.de
    Nov 20, 2006
Loading...

Share This Page