in reply to Re^3: Update XML Values using two primary keys
in thread Update XML Values using two primary keys
The HoH worked, Thank you. Since the HoH is not sorted so how can we compare the key of hashes with the node latitude and longitude and update the names. For e.g. what should be the condition in the if statement?
my $inputfile = 'test_data.csv'; my $csv = Text::CSV->new ({binary => 1,auto_diag => 1,sep_char =>';'} +); open(my $data, '<:encoding(utf8)', $inputfile) or die "Could not open +'$inputfile' $!\n"; my $header = $csv->getline($data); $csv->column_names($header); my %HoH; while (my $row = $csv->getline_hr($data)) { my $key = "$row->{latitude}.$row->{longitude}"; # Compare next if exists $HoH{$key} && $row->{id} >= $HoH{$key}->{id}; # Set (or overwrite) $HoH{$key} = {name => $row->{name},id => $row->{id}}; } foreach my $key1 (keys %HoH) { print "'$key1'\n"; foreach my $key2 (keys %{$HoH{$key1}}) { print $key2=$HoH{$key1}{$key2},"\n"; } } my $myhash = \%HoH; my $dom = 'XML::LibXML'->load_xml(location => 'test.osm'); for my $node ($dom->findnodes('/osm/node')) { my $tag = $node->findnodes('tag[@k="name"]')->[0]; print $tag,"\n"; if () { } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Update XML Values using two primary keys
by hippo (Archbishop) on Jan 11, 2021 at 12:23 UTC | |
by pratikpooja (Novice) on Jan 11, 2021 at 21:20 UTC | |
by hippo (Archbishop) on Jan 11, 2021 at 23:05 UTC | |
by pratikpooja (Novice) on Jan 12, 2021 at 17:43 UTC | |
by AnomalousMonk (Archbishop) on Jan 12, 2021 at 20:03 UTC | |
| |
by AnomalousMonk (Archbishop) on Jan 11, 2021 at 23:24 UTC | |
by pratikpooja (Novice) on Jan 12, 2021 at 17:49 UTC |