Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

yodabjorn's scratchpad

by yodabjorn (Monk)
on Jun 01, 2004 at 22:16 UTC ( #358672=scratchpad: print w/replies, xml ) Need Help??

Unrolling nested hashes.
#!/usr/bin/perl use strict ; my %struct ; $struct{foo}{1} = "one" ; $struct{bar}{2} = "two" ; foreach my $hash ( keys (%struct) ) { print "$hash \n"; foreach my $key ( keys ( %{$struct{$hash}} ) ) { print "\t$key \n" ; } }

[id://castaway]'s code:
#!/usr/bin/perl -w use Data::Dumper; my $hashtest; $hashtest->{'abc'}->{'filename'} = 'fred'; $hashtest->{'def'}->{'filen +ame'} = 'harry'; foreach $v (values (%{$hashtest})) { $testhash->{$v->{'filename'}} = 1; } print Dumper($testhash);

My version to get his desired results:
#!/usr/bin/perl use warnings ; # perl5 adn above use strict ; # always! use Data::Dumper; my @files ; my %hashtest; # load some dummy data $hashtest{'abc'}{'filename'} = 'fred'; $hashtest{'def'}{'filename'} = 'harry'; # unfold outter has keys foreach my $key (keys (%hashtest)) { # push the file name ont @files. # printing $hashtest{$key}{'filename'} etc would # be apropriate as well push @files, $hashtest{$key}{'filename'} ; } print Dumper(\@files);
Log In?

What's my password?
Create A New User
[marto]: hmm, may have to patch CPAN::Meta to move from search.cpan to metacpan in the META.json/yml files
[Corion]: marto: Heh - it seems that they plan to keep the links alive for a long time. But still, I plan on moving PM to use/generate the new links
[Corion]: And I think it's better to generate links to the new world instead of keeping the older links alive by generating new versions of them ;)
[marto]: yeah, I guess it's supposed to be a permanent redirect, but better to make the move where possible

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2018-05-23 09:22 GMT
Find Nodes?
    Voting Booth?