Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

problem using new perl version

by supernono06 (Initiate)
on Nov 08, 2018 at 16:01 UTC ( #1225431=perlquestion: print w/replies, xml ) Need Help??
supernono06 has asked for the wisdom of the Perl Monks concerning the following question:

Hi everybody, I am a beginner and I need your help. I use Windows 10. I have an old perl script which was perfectly running using Perl Now I have installed Strawberryperl and I get an error message: "Can't use 'defined(%hash)' (Maybe you should just omit the defined()?) at line 4191." In my script (, this corresponds to the following line: "if (defined %function_array_name) {" Can you please explain me the meaning of this error and guide me how to fix it? Thanks. Supernono06

Replies are listed 'Best First'.
Re: problem using new perl version -- defined hash
by Discipulus (Monsignor) on Nov 08, 2018 at 16:13 UTC
    Hello supernono06 and welcome to the monastery and to the wonderful world of Perl!

    You can also profit the read of the main documentation for defined especially:

    Use of defined on aggregates (hashes and arrays) is no longer supporte +d. It used to report whether memory for that aggregate had ever been +allocated. You should instead use a simple test for size: if (@an_array) { print "has array elements\n" } if (%a_hash) { print "has hash members\n" }


    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: problem using new perl version
by marto (Archbishop) on Nov 08, 2018 at 16:08 UTC
Re: problem using new perl version
by 1nickt (Abbot) on Nov 08, 2018 at 16:06 UTC

    Hi, you can often get more information with diagnostics:

    $ perl -Mstrict -Mdiagnostics -wE 'my %foo; say 1 if defined %foo' Can't use 'defined(%hash)' (Maybe you should just omit the defined()?) + at -e line 1 (#1) (F) defined() is not usually right on hashes. Although defined %hash is false on a plain not-yet-used hash, it becomes true in several non-obvious circumstances, including itera +tors, weak references, stash names, even remaining true after undef %has +h. These things make defined %hash fairly useless in practice, so it +now generates a fatal error. If a check for non-empty is what you wanted then just put it in bo +olean context (see "Scalar values" in perldata): if (%hash) { # not empty } If you had defined %Foo::Bar::QUUX to check whether such a package variable exists then that's never really been reliable, and isn't a good way to enquire about the features of a package, or whether it's loaded, etc. Uncaught exception from user code: Can't use 'defined(%hash)' (Maybe you should just omit the defined +()?) at -e line 1.

    Hope this helps!

    The way forward always starts with a minimal test.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1225431]
Approved by marto
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2019-01-21 21:42 GMT
Find Nodes?
    Voting Booth?
    After Perl5, I'm mostly interested in:

    Results (370 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!