in reply to can I change hash keys or values directly

I came here to this thread to give my answer for your question. After reading the responses given by other monks I found out that absolutely the same answer has already been given by choroba. The code below is just example of the suggestion by choroba and mine.
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my $x = { a => [ 1, 2 ], c => [ qw( a b c ) ], d => 100 }; print 'original: ', Dumper $x; # one by one replacement: c -> b, d -> c $x->{b} = delete $x->{c}; $x->{c} = delete $x->{d}; print 'modified: ', Dumper $x; # in one run replacement: b, c -> c, d @$x{qw( c d )} = delete @$x{qw( b c )}; print 'reverted: ', Dumper $x;

Replies are listed 'Best First'.
Re^2: can I change hash keys or values directly
by misterperl (Friar) on Jan 29, 2021 at 14:27 UTC
    I appreciate the replies guys. I guess I was already on the best approach using the slice. The link to "values" and it's helpful to know that they be operated on directly. I tried it
    map s.(\d+).$1+1/e,values %nums;
    which worked great. Love it. Helpful & useful. TYVM

    If I'm reading that right, it does appear from that link that as an experiment, perhaps keys also worked that way for some brief Perl versions:

    use 5.012; # so keys/values/each work on arrays
      > perhaps keys also worked that way

      No, it means you can write

      #!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use Syntax::Construct qw{ keys-array }; # More explicit than 5.012. my @array = qw( abc def ); my @keys = keys @array; # 0, 1 my @values = values @array; # abc, def while (my ($index, $value) = each @array) { say "$index $value"; # 0 abc, 1 def }

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]