in reply to Re^9: manipulating cpio archive
in thread manipulating cpio archive

The only flaw of the old code is that it directly compares elements from @{ $cpio->{list} } against the filenames. That is wrong because the elements in @{ $cpio->{list} } are Archive::Cpio::File objects. Instead, it should compare the elements against the ->name property. Most likely (but untested) like so:

sub remove { my ($cpio, @filenames) = @_; $cpio->{list} or die "can't remove from nothing\n"; # Create a lookup table of names to be removed my %filenames = map { $_ => 1 } @filenames; # This was the old, buggy code # @{$cpio->{list}} = grep { !$filenames{$_} } @{$cpio->{list}}; # Remove the elements according to their name: @{$cpio->{list}} = grep { !$filenames{$_->name} } @{$cpio->{list}} +; }

Replies are listed 'Best First'.
Re^11: manipulating cpio archive
by momo33 (Beadle) on Jan 18, 2011 at 09:26 UTC
    This seems to work (the first output was correct)
    Thank you!

      The author has just released Archive::Cpio v0.08, which contains the fix.