Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

problem using new perl version

by supernono06 (Initiate)
on Nov 08, 2018 at 16:01 UTC ( [id://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 5.6.1.635. Now I have installed Strawberryperl 5.28.0.1 and I get an error message: "Can't use 'defined(%hash)' (Maybe you should just omit the defined()?) at ucode.pl line 4191." In my script (ucode.pl), 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 (Canon) 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" }

    L*

    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 (Cardinal) on Nov 08, 2018 at 16:08 UTC
Re: problem using new perl version
by 1nickt (Canon) 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found