cmv has asked for the wisdom of the Perl Monks concerning the following question:
I'm a little embarrassed to ask this question, as I feel I should know the answer - however, I haven't been able to come up with a good answer (by searching or thinking) for 2 days! Please help - my mind is going...
I want to declare a hash-of-hashes, where some of the elements point to each other. Is it possible to do it in a declaration? Here is some code that makes it happen outside the declaration.
Any help is much appreciated!
Thanks
-Craig
use strict; use warnings; use Data::Dumper; my %fields = ( version1 => { 1 => 'Field 1', 2 => 'Field 2', 3 => 'Field 3', }, version2 => { 1 => 'Field 1', 2 => 'Field 2', 3 => 'Field 3', 4 => 'Field 4', }, version3 => { 1 => 'Field 1', 2 => 'Field 2', 3 => 'Field 3', 4 => 'Field 4', 5 => 'Field 5', }, version4 => { # What if version4 is exactly the same as version3. # How do I just make version4 point to verson3? }, ); print STDERR "fields Dump1:\n", Dumper(\%fields), "\n"; $fields{version4} = $fields{version3}; print STDERR "fields Dump2:\n", Dumper(\%fields), "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Creating pointers in a HoH declaration
by AnomalousMonk (Archbishop) on Apr 29, 2016 at 18:56 UTC | |
|
Re: Creating pointers in a HoH declaration
by NetWallah (Canon) on Apr 29, 2016 at 20:43 UTC | |
|
Re: Creating pointers in a HoH declaration
by graff (Chancellor) on Apr 30, 2016 at 16:11 UTC |