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

Good Evening Fine monks. I've come to a bump in the road with my perl script when I execute the script it loads up fine with this exception. I must also state that this is perl 5.16.3 running on Windows 7 64 bit and this same script runs with out error on WinXP :
defined(@array) is deprecated at C:/Perl64/site/lib/PDF/Reuse.pm line 993 (#1) (D deprecated) defined() is not usually on arrays because it checks for an undefined scalar value. If you want to see if the array is empty, just use if (@array) { # not empty } for example. (Maybe you should just omit the defined()?)
As stated my script loads fine below is the code from the Reuse.pm

my $tSida = $sida + 1; if ((@annots) || (defined @{$links{'-1'}}) || (defined @{$links{$tSida +}})) { $sidObjekt .='/Annots ' . mergeLinks() . ' 0 R'; }

Replies are listed 'Best First'.
Re: Define(@array) is Deprecated
by davido (Cardinal) on Mar 10, 2014 at 22:54 UTC

    Yes, that message is correct:

    $ perl -Mwarnings -Mdiagnostics -e '@array = (1,2,3); print defined(@a +rray)' defined(@array) is deprecated at -e line 1 (#1) (D deprecated) defined() is not usually useful on arrays because i +t checks for an undefined scalar value. If you want to see if the array is empty, just use if (@array) { # not empty } for example.

    Your code:

    my $tSida = $sida + 1; if ((@annots) || (defined @{$links{'-1'}}) || (defined @{$links{$tSida +}})) { $sidObjekt .='/Annots ' . mergeLinks() . ' 0 R'; }

    Would be better written as...

    my $tSida = $sida + 1; if( @annots || @{$links{'-1'}} || @{$links{$tSida}} ) { $sidObjekt .= '/Annots ' . mergLinks() . ' 0 R'; }

    Your use of defined is presumably to determine if the array ref stored in $links{'-1'} contains values. If instead you want to determine if $links{'-1'} exists, use exists. If you want to see if $links{'-1'} is defined, use defined without dereferencing the element. And if you want to see if it contains an anonymous array, you can use ref or Scalar::Util::reftype()


    Dave

      Thanks davido! That did the trick. I am finding as I move perl scripts from one version of perl to another even the updated perl modules need some tweeking in order to function accordingly. Thanks again!.

Re: Define(@array) is Deprecated
by kcott (Archbishop) on Mar 10, 2014 at 23:42 UTC

    G'day PilotinControl,

    There was a change to that deprecation warning in v5.16.0 (see perl5160delta: New Diagnostics).

    "The long-deprecated defined(@array) now also warns for package variables. Previously it issued a warning for lexical variables only."

    There was a bug report raised for this issue 8 months ago: Bug #77800 for PDF-Reuse: Deprecation Warnings in Perl 5.16.0

    PDF::Reuse (v0.35) (the current version at the time of writing) has not changed in ~6 years. There have been bugs raised over its lifetime: at least 13 appear to be for this specific version and all remain active (see Active bugs for PDF-Reuse).

    I don't personally have any knowledge of this module, but it's quite possible that maintenance has been abandoned. Your options would seem to be:

    • Do nothing and put up with the warnings.
    • Attempt to contact the author and determine the status of this module.
    • Take over maintenance of this module and fix it yourself.
    • Find an alternative module which provides sufficiently similar functionality for your requirements.
    • Write your own module that provides exactly the functionality you want.

    By the way, check the version of Perl you're running on "WinXP": if it's earlier than 5.16.0, that would explain why the warnings are absent there.

    -- Ken

Re: Define(@array) is Deprecated
by choroba (Cardinal) on Mar 10, 2014 at 22:46 UTC
    What is the question? Does the code work if you just remove defined?
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Define(@array) is Deprecated
by boftx (Deacon) on Mar 10, 2014 at 22:58 UTC

    I might be wrong, but it looks like $links is (or should be) a hash of array refs, in which case it doesn't make sense to me to use the @{$links{$elementname}} instead of simply defined( $links{$elementname} ) to see if the element has been populated to begin with.

    In fact, it looks like you need to check for the element's existence and if it has members in the array being referenced by it. I'd have to double check, but I think doing if ( @{$hash{element}} ) might throw a warning if the element does not exist or contains undef.

    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.