Hello Monks:

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 :

my $member = $appendMemberArr[2]; 2555 print "member->fileName=".$member->fileName()."\n";

See rest of code here:

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 } }

In reply to Archive::Zip: Passing members to subroutines by stephen.baldwin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.