Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Hash Curious

by choroba (Archbishop)
on Oct 15, 2021 at 23:34 UTC ( #11137615=note: print w/replies, xml ) Need Help??


in reply to Hash Curious

See Slices.

Also, it's faster than assigning the keys one by one, as the loop runs in C rather than Perl.

#!/usr/bin/perl use warnings; use strict; my @keys = 'a' .. 'z'; sub one_by_one { my %hash; undef $hash{$_} for @keys; } sub slice { my %hash; @hash{@keys} = (); } use Benchmark qw{ cmpthese }; cmpthese(-3, { one_by_one => \&one_by_one, slice => \&slice, }); __END__ Rate one_by_one slice one_by_one 267946/s -- -25% slice 359541/s 34% --

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://11137615]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2022-01-25 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (67 votes). Check out past polls.

    Notices?