in reply to Archive::Zip: Passing members to subroutines

ERROR Can't locate object method "fileName" via package "Archive::Zip::ZipFileMember=HASH(0x3d99cdc)"

Somewhere in your code, you converted the reference to 0x3d99cdc to a string, and now you're trying to call methods on this string. That doesn't work.

I think this happens here:

push @appendArr,("$idArr[$c],$command,$srcArr[$c],$destArr[$c],$cmdArg +s");

If instead of converting all those nice references to a string you use an array, you keep the references as references:

push @appendArr,[$idArr[$c],$command,$srcArr[$c],$destArr[$c],$cmdArgs +];

Later, don't split that string, but use it as array immediately:

# (my @appendMemberArr) = split(/,/,$fAppend); (my @appendMemberArr) = @$fAppend;

Replies are listed 'Best First'.
Re^2: Archive::Zip: Passing members to subroutines
by Anonymous Monk on Feb 01, 2018 at 15:34 UTC
    Hello Corion: Thank you so much for your prompt reply. You were of course 100% correct! That was the offending line. In the end I opted to keep everything in one array:
    push @appendArr,([$idArr[$c],$command,$srcArr[$c],$destArr[$c],$cmdArg +s]);
    and access it thus:
    foreach $fAppend (@appendArr) { print "is an array\n" if (ref($fAppend) eq "ARRAY"); print "fAppend[0]=@$fAppend[0]\n"; print "fAppend[2]=".(@$fAppend[2])->fileName()."\n"; print "fAppend[2]=".(@$fAppend[2])->contents()."\n"; ...
    If you have time and inclination, could you expound on what is going on with the referencing and typing?

    I presume the original ZIP "member" object is a hash reference.

    The array was originally passed through as a scalar \@ then plopped into a string.

    And as you pointed out, it lost its array-ness and hash-ness when I pushed it in a string "...,$member,..." into @appendArr. How does that happen?

    If you have any reading recommendations on these intricacies, I'd be pleased to receive them!

    Thanks again for your help!

    We are up and running.

    Rgds

    Steve

      Converting something to a string is mostly a one-way road.

      You can only interchangeably use a string as a number or a string. There is no (sane) way to convert a string back to a reference in Perl.

      The process of converting something to a string is called "stringification" in Perl. I'm not sure what you mean by "how does that happen" - I could explain to you how Perl constructs a string in which you use variables, or I could guess about how you wrote code that did that, but I'm not sure that any of these would give you the information you really seek.