PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:

Good Morning Monks.
I'm getting the following error: "can't use an undefined value as an ARRAY reference at: C:/Perl64/site/lib/PDF/Reuse.pm line 995
PDF::Reuse::skrivSida() called at C:/Perl64/site/lib/PDF/Reuse.pm line 1017
The entire section of code from the PDF/Reuse.pm module is below. This code works fine on WinXP and not on Win7 as stated in my previous posts. Thanks in advance.

$stream = ''; my $tSida = $sida + 1; # OLD PERL WINXP #if ((@annots) #|| (defined @{$links{'-1'}}) #|| (defined @{$links{$tSida}})) if( @annots || @{$links{'-1'}} || @{$links{$tSida}} ) { $sidObjekt .= '/Annots ' . mergeLinks() . ' 0 R'; } if (defined $AAPageSaved) { $sidObjekt .= "/AA $AAPageSaved"; undef $AAPageSaved; } $sidObjekt .= ">>endobj\n"; $objekt[$sidObjNr] = $pos; $pos += syswrite UTFIL, $sidObjekt; push @{$kids[0]}, $sidObjNr; $sida++; $counts[0]++; if ($counts[0] > 9) { ordnaNoder(8); } } sub prEnd { if (! $pos) { return; } if ($stream) { skrivSida(); } skrivUtNoder();

Replies are listed 'Best First'.
Re: Can't use undefined value as an ARRAY reference
by davido (Cardinal) on Mar 15, 2014 at 16:17 UTC

    There are at least three places in the code you demonstrated where that module is treating a scalar like an array reference. In the code you posted, that happens twice on line 8, and once on line 18. We don't know if what you posted is line 995, or line 1017 from the module... and I don't really feel like pulling the module into an editor to find out.... that's your job. ;)

    I do know that the source code for that module currently on CPAN looks slightly different from what you posted, which indicates to me that you may not be using the most up-to-date version. The first difference I noticed is that the current version doesn't have the commented-out section of code that starts with # OLD PERL WINXP

    So you're probably not running the most recent (v0.35, from 2008!) version of the module. Either that, or you have, or someone has modified the source of the version you are using.

    We also know nothing about the context in which you're getting this error. What code is calling this module? And how was the module installed? Is it possible that some components are missing? What is different between your old Win system and your new one?

    It's a very difficult question to answer because of the absence of information provided to us. But I would be asking myself why the version of the module I'm using looks different (even if just superficially) than the six year old (newest) version on CPAN.


    Dave

      Below are the particulars:
      Computer 1: WinXP, Perl 5.10.0 Activestate, PDF-Reuse v35
      Computer 2: Win7, Perl 5.16.3 Activestate, PDF-Reuse v35
      Modules were installed using a mixture of PPM and CPAN

      WINXP REUSE PM UN EDITED $stream = ''; my $tSida = $sida + 1; if ((@annots) || (defined @{$links{'-1'}}) || (defined @{$links{$tSida}})) { $sidObjekt .= '/Annots ' . mergeLinks() . ' 0 R'; } if (defined $AAPageSaved) { $sidObjekt .= "/AA $AAPageSaved"; undef $AAPageSaved; } $sidObjekt .= ">>endobj\n"; $objekt[$sidObjNr] = $pos; $pos += syswrite UTFIL, $sidObjekt; push @{$kids[0]}, $sidObjNr; $sida++; $counts[0]++; if ($counts[0] > 9) { ordnaNoder(8); } } sub prEnd { if (! $pos) { return; } if ($stream) { skrivSida(); } skrivUtNoder(); if($docProxy) { $docProxy->write_objects; undef $docProxy; # Break circular refs }

      Windows 7 code edited using a suggestion from a fellow monk which fixed the error regarding a symbol reference.

      $stream = ''; my $tSida = $sida + 1; #if ((@annots) #|| (defined @{$links{'-1'}}) #|| (defined @{$links{$tSida}})) if(@annots || @{$links{'-1'}} || @{links{$tSida}} ) # LINE 995 { $sidObjekt .= '/Annots ' . mergeLinks() . ' 0 R'; } if (defined $AAPageSaved) { $sidObjekt .= "/AA $AAPageSaved"; undef $AAPageSaved; } $sidObjekt .= ">>endobj\n"; $objekt[$sidObjNr] = $pos; $pos += syswrite UTFIL, $sidObjekt; push @{$kids[0]}, $sidObjNr; $sida++; $counts[0]++; if ($counts[0] > 9) { ordnaNoder(8); } } sub prEnd { if (! $pos) { return; } if ($stream) # LINE 1017 { skrivSida(); } skrivUtNoder(); if($docProxy) { $docProxy->write_objects; undef $docProxy; # Break circular refs }

      And here is the code that is used to callback to the Reuse.pm in the script:

      prEnd;

        So your Perl version is different, for one thing. And you're installing it using a combination of PPM and cpan... seems odd. And you've modified the source code of the module, possibly without fully understanding what the modification is for. Those are at least three opportunities for trouble to creep in, without even considering the potential for bugs within the module itself.

        Speaking of which, I found this: RT#77800, which deals specifically with a problem that turns up under Perl 5.16.x and newer, relating to deprecation warnings... not the same type of warning you're getting, but definitely within the same code segment.

        I don't know the answer to the question I'm about to ask, because I do my best to avoid working with PDF's: Is it possible that there is a newer, better maintained module on CPAN that can be of use to you, that doesn't have bugs in its queue that are --in some cases-- several years old?

        Anyway, try rolling your Perl version back to an earlier version -- preferably the same version you're using on the old Windows machine -- and see if it works then. If so, you've found another bug to report, though I don't think anyone is monitoring the reports at this point.

        It sounds like you're using ActiveState. It appears that Perl-5.10.x is available from ActiveState for a fee. You might, instead, download the Strawberry Perl Perl v5.10.1 in a sandboxed dev environment and see if the module works under that Perl. If so, and if you still are required to use ActivePerl in production, you'll at least know whether or not its worthwhile investigating what ActiveState charges for 5.10.


        Dave

Re: Can't use undefined value as an ARRAY reference
by kcott (Archbishop) on Mar 15, 2014 at 22:35 UTC

    G'day PilotinControl,

    It would have been appropriate to state, at the outset, that the PDF/Reuse.pm code you're using is a private copy which you have personally edited.

    A link to Define(@array) is Deprecated (from earlier this week) would have shown what the changes were and why you made them.

    Not doing this has caused unnecessary and duplicated effort. Specifically:

    We're happy to help and do so freely. Our time is finite and we don't want to waste it with unnecessary tasks or repeating the work already done by others. Please consider this in any future posts.

    -- Ken

      As an update to the original question which has been solved by doing this: Backdating to using Activestate Perl 5.10 with no errors running on Windows 7. Thanks to those who provided their suggestions they have been much appreciated.