Use of each() on hash after insertion without resetting hash iterator results in undefined behavior, Perl interpreter: 0xed8cd8 at ./each-example.pl line 21.
####
Use of each() on hash after insertion without resetting hash iterator results in undefined behavior, Perl interpreter: 0x.
####
#!/usr/bin/env perl
use strict;
use warnings;
EXAMPLE:
{
my $happy_camper =
{
Rambler => 'The Yellow Rose of Texas',
Wagon => 'There may be flies on them there guys but there are 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 )
{
while ( my ( $_key , $_val ) = each % $happy_camper )
{
if ( int(rand 300000) == 1 )
{
# printf STDERR "# Adding new item\n";
$happy_camper->{ ++$newkeys }
= 'Shame on you!';
#( keys % $happy_camper )[ int(rand scalar keys % $happy_camper ) ];
}
}
# if (( int rand 2000 ) == 0 )
# {
# foreach my $_key ( sort keys % $happy_camper )
# {
# printf "# %-12s ->> %s\n", $_key, $happy_camper->{ $_key };
# }
# }
}
}
exit 0;
## END