in reply to Define(@array) is Deprecated
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Define(@array) is Deprecated
by PilotinControl (Pilgrim) on Mar 10, 2014 at 23:08 UTC |