Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Experimental keys on scalar is now forbidden

by haukex (Archbishop)
on May 09, 2018 at 10:45 UTC ( [id://1214268]=note: print w/replies, xml ) Need Help??


in reply to Experimental keys on scalar is now forbidden

my @variants = keys $hash{$word}{variants};
What is the right way to write it now?

The "right" way to write it, or rather, the way that will work on any version of Perl 5, is:

my @variants = keys %{ $hash{$word}{variants} };

Update: See also perlreftut, perlref, perldsc, and Experimental push on scalar now forbidden.

As of Perl 5.24, you can also make use of the Postfix Dereference Syntax:

use 5.024; my @variants = keys $hash{$word}{variants}->%*;

(Update 2: It's actually been present since 5.20, but it was still experimental then and had to be explicitly enabled.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1214268]
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: (3)
As of 2024-04-26 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found