Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: can I change hash keys or values directly

by misterperl (Pilgrim)
on Jan 29, 2021 at 14:27 UTC ( [id://11127637]=note: print w/replies, xml ) Need Help??


in reply to Re: can I change hash keys or values directly
in thread can I change hash keys or values directly

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

Replies are listed 'Best First'.
Re^3: can I change hash keys or values directly
by choroba (Cardinal) on Jan 29, 2021 at 22:44 UTC
    > 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]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11127637]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (11)
As of 2024-04-18 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found