stephen.baldwin has asked for the wisdom of the Perl Monks concerning the following question:
I have a strange problem. If anyone can explain what is going wrong with the code below, please give me a shout.
I know there are multiple ways to skin the cat so-to-speak so I don't need "why don't you do it this way instead" answers -- just what is wrong with the edited code below.
Context:
This is an involved way of building a directory and file structure from a variety of sources, including a ZIP file. The ZIP member contents should be appended to an existing version of that file if found.
1. Basically I am extracting a member from the ZIP file fine.2. I am adding the member ($member) to an array (@srcArr) and passing the array reference \@ through to a subroutine (CopyFile()). All fine
3. CopyFile: I am extracting the ZIP member and for debug printing the filename and the contents. This all works well.
4. CopyFile: The member is pushed onto another array @appendArr for later processing.
5. CopyFile: When the member is popped off the @appendArr array, nothing works (member->fileName() etc.)
ERROR Can't locate object method "fileName" via package "Archive::Zip::ZipFileMember=HASH(0x3d99cdc)" (perhaps you forgot to load "Archive::Zip::ZipFileMember=HASH(0x3d99cdc)"?) at C:\Users\e5313240\Documents\FIS\MB\Perl\Assignment.pl line 2555.
Here is the relvant code segment :
See rest of code here:my $member = $appendMemberArr[2]; 2555 print "member->fileName=".$member->fileName()."\n";
use Archive::Zip; my $fZipIn = Archive::Zip->new($fSource) or die "### ERROR $thisFunc(" +.__LINE__."): FAILED TO CREATE ZIP FOR $fSource\n"; my @zMemberArr = $fZipIn->members(); # loop here for processing each member [stored in $member] push @srcArr, ($member); CopyFile(\@idArr,\@cmdArr,\@srcArr,\@destArr,[]); } sub CopyFile # the bit we like is $_[2] { my @srcArr = @{$_[2]}; # looping through each @srcArr - counter is $c print $gfLog "append found $srcArr[$c] ".$srcArr[$c]->fileName()."\n +"; if ($idArr[$c] eq "ZIP") { print "contents>>>\n".$srcArr[$c]->contents()."\n<<<contents\n"; # + <=== BUT THIS WORKS FINE } # adding it to the appendArr for later processing push @appendArr,("$idArr[$c],$command,$srcArr[$c],$destArr[$c],$cmdA +rgs"); # lots of processing later, we want to process our appendArr # 0 is type # 1 is command # 2 is source # 3 is dest # 4 is file commands my $fAppend; foreach $fAppend (@appendArr) { print $gfLog "fAppend=$fAppend\n"; (my @appendMemberArr) = split(/,/,$fAppend); print $gfLog "$thisFunc: Processing append: $appendMemberArr[0] $a +ppendMemberArr[2]\n"; mkpath(dirname $appendMemberArr[3]) if (! -d dirname($appendMember +Arr[3])); if ($appendMemberArr[0] eq "ZIP") { my $member = $appendMemberArr[2]; print "member->fileName=".$member->fileName()."\n"; # <=== THIS +IS THE ERROR # other processing } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Archive::Zip: Passing members to subroutines
by Corion (Patriarch) on Jan 31, 2018 at 21:28 UTC | |
by Anonymous Monk on Feb 01, 2018 at 15:34 UTC | |
by Corion (Patriarch) on Feb 01, 2018 at 15:38 UTC |