natxo has asked for the wisdom of the Perl Monks concerning the following question:

running perl 5.20 every time my script runs I get that warning. Is there a way to silence it without ommiting 'use warnings;'? The warning comes from this code:
while ( my ( $key, $value) = each $HoA ) { print $key . " "; for ( @$value ) { print "$_ "; } }
The script works perfectly fine otherwise, this is just a cosmetic annoyance as far as I am concerned.

Update:

Thanks for both suggestions, very informative.

Replies are listed 'Best First'.
Re: each on reference is experimental at
by Corion (Patriarch) on Sep 28, 2015 at 12:52 UTC

    Replace

    each $HoA

    by

    each %$HoA

    to silence the warning and guard yourself from when each on reference might be removed again.

Re: each on reference is experimental at
by Athanasius (Archbishop) on Sep 28, 2015 at 13:01 UTC

    Hello natxo,

    Corion’s solution is preferable, but this does what you want:

    #! perl use strict; use warnings; my $HoA = { vowels => [ 'a', 'e', 'i', 'o', 'u', ], primes => [ 2, 3, 5, 7, 11, ], }; { no warnings 'experimental'; while (my ($key, $value) = each $HoA) { print $key . " "; for (@$value) { print "$_ "; } } }

    Output:

    22:59 > perl 1386_SoPW.pl vowels a e i o u primes 2 3 5 7 11 22:59 >

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      I think this particular feature is likely to be removedThis particular feature has been removed from newer versions of Perl, so it's definitely not the best solution.

      Also, there's no reason to disable all experimental warnings when you can just disable the one in question.

      no warnings qw( experimental::autoderef ); # 5.18+
      or
      no if $] >= 5.018, warnings => "experimental::autoderef"; # 5.14+
Re: each on reference is experimental at
by Anonymous Monk on Sep 28, 2015 at 15:57 UTC
    If something is called "experimental," I would not bet my app on it. Corion offers the best solution.

      I concur with this. However, you can always check in on the status and future viability of experiments, along with all current/accepted/rejected experiments by reading the most current dev version (which is at this time, 5.23) of perlexperiment. You can then drill down from there to the actual ticket for the experiment to check in on how things are going.

      I'm not sure if accepted experiments are candidates for further changes, but perlexperment does say the following: "These features were so wildly successful and played so well with others that we decided to remove their experimental status and admit them as full, stable features in the world of Perl, lavishing all the benefits and luxuries thereof. They are also awarded +5 Stability and +3 Charisma.". Does anyone know if once deemed 'stable', that they won't change again?

      Update: I found the answer in perlpolicy. It doesn't look like an accepted experiment is subject to further change: "a feature present in v5.20.0 may be marked no longer experimental in v5.22.0 if and only if its behavior is unchanged throughout all of v5.21."/Update

      The particular experiment discussed in this thread, "Array and hash container functions accept references", hasn't had a ticket update since 2013, but it's still listed as a current experiment as they steamroll toward the v5.24 official release.

      Note that ikegami in Re^2: each on reference is experimental at said that this feature may be has been deprecated/ removed, and he's someone I'd definitely listen to for such matters. dave_the_m has also confirmed this in the note following this one.

      -stevieb

        As of 5.23.1, using a ref with push, keys, each etc croaks. Looks like we forgot to update perlexperiment.pod though.

        Dave.

        Does anyone know if once deemed 'stable', that they won't change again?

        By "full, stable features in the world of Perl, lavishing all the benefits and luxuries thereof", perlexperiment means the feature is no longer experimental, that it's as much a part of Perl as any other. One of the "benefits and luxiries" is Perl's backwards compatibility policy. Perl is subject to strict backwards compatibility requirements. Backwards incompatible changes are sometimes made, but not lightly.