in reply to Mapping data structures through external source
#!/usr/bin/perl use warnings; use strict; use Data::Diver qw{ Dive }; my $external_structure = { ... }; my %format = (product_id => ['id'], price_excl_vat => [qw[ data price ]], unit_qty => [qw[ data unit_info qty ]]); # (1) my $internal_structure = {}; for my $key (keys %format) { $internal_structure->{$key} = Dive($external_structure, @{ $format{$key} }); } use Data::Dumper; print Dumper $internal_structure;
(1) Note that the second element of the path is unit_info, not just unit.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Mapping data structures through external source
by Aldebaran (Curate) on Aug 02, 2019 at 19:33 UTC | |
|
Re^2: Mapping data structures through external source
by DreamT (Pilgrim) on Aug 05, 2019 at 07:43 UTC | |
by haukex (Archbishop) on Aug 05, 2019 at 09:07 UTC |