On Fri, 23 Feb 2018 15:46:14 +0100
"jose cabrera" <[email protected]> wrote:
> Greetings!
>
> I am using perl v5.22.1, and I am debugging an old script. The code
> is,
>
> if (defined($$glob)) {
> $localconfig{$var} = $$glob;
> }
> elsif (defined (@$glob)) {
> $localconfig{$var} = \@$glob;
> }
> elsif (defined (%$glob)) {
> $localconfig{$var} = \%$glob;
> }
>
> when I run it, the interpreter errors out with:
>
> Can't use 'defined(@array)' (Maybe you should just omit the
> defined()?) at Bugzilla/Install/Localconfig.pm line 239, <DATA> line
> 755.
>
> Any thoughts? Thanks.
At a quick glance, it sounds like that script ought to be changed to
use ref() to see what kind of reference it got, e.g.:
if (ref $glob eq 'SCALAR') {
$localconfig{$var} = $$glob;
} else {
$localconfig{$var} = $glob;
}
That approach avoids the somewhat pointless de-ref and re-ref of
hashrefs/arrayrefs that the old code did - *unless* it does that for
good reason, i.e. it will be changing it and doesn't want a reference
but a shallow copy.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/