in reply to To each() their own
I took the pragmatic approach and re-coded the loop to use a foreach() loop over (keys %$happy_camper) instead of trying to get the combined key,val each() iterator to work. I haven't had trouble adding keys with a foreach loop like below. Tested on Perl 5.20 MSWin32.
#!/usr/bin/env perl use strict; use warnings; use Data::Dump qw(pp); EXAMPLE: { my $happy_camper = { Rambler => 'The Yellow Rose of Texas', Wagon => 'There may be flies on them there guys but there ar +e no flies on us', Caskit => 'The Rain in Spain goes mainly down the drain', Skate => 'The Quick Brown Fox Jumped Over The Lazy Dogs Back +', Lemon => 'Love the smell of napalm in the morning' }; my $newkeys = 'KEYME000'; foreach ( 1 .. 900000 ) { foreach my $_key (keys %$happy_camper) { if ( int(rand 300000) == 1 ) { $happy_camper->{ ++$newkeys } = 'Shame on you!'; } } } pp $happy_camper; } exit 0;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: To each() their own
by Ancient.Wizard (Novice) on May 02, 2017 at 12:29 UTC |