in reply to desire hard ref alternative
#!/usr/bin/perl use warnings; use strict; my %hash = ( 1 => { one => q() }, 2 => { two => q(), zwei => q(), dos => q() }, 3 => { three => q(), tres => q() }, 4 => { four => q() }, 5 => { five => q() }, 6 => { six => q(), seis => q() }, 7 => { seven => q() }, ); my $valCount; for my $item (keys %hash) { my $count = keys %{ $hash{$item} }; print "count is $count\n"; $valCount += $count; } my %subs; my $recCount; while ($valCount > 0) { for my $id (sort keys %hash) { if (not exists $subs{$id}) { my $href = $hash{$id}; for my $word (sort keys %$href) { next if 'written' eq $href->{$word}; $valCount--; print "$id $word\n"; $subs{$id} = q(); $href->{$word} = 'written'; last if keys %{ $hash{$id} } > 1; } $recCount++; if ($recCount == 4) { $recCount = 0; %subs = (); } } } }
Generally, you'd need to introduce one more layer to store the original value and the new hash:
my %hash = ( 1 => { one => { value => 'v' }, ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: desire hard ref alternative
by plevine (Initiate) on Aug 15, 2014 at 22:47 UTC |