but if the 2nd Hash key is not present or rejected then it should get added as new tag in XML.

You can only tell if it is not present after you have trawled through all of the XML nodes, so the logic is this:

  1. Loop over each XML node, if the HoH has the key then use it and then delete it from the HoH
  2. After looping over all the nodes, all the remaining HoH keys are extras to be added, so loop over those keys (sorted if you like) and add them to the XML
#!/usr/bin/env perl use strict; use warnings; my @nodes = qw/foo quux baz/; my %HoH = ( foo => { day => 'Mon' }, bar => { day => 'Tue' }, baz => { day => 'Wed' } ); # Loop over nodes for my $node (@nodes) { if (exists $HoH{$node}) { print "Node $node found in HoH and deleted\n"; # Do more processing here delete $HoH{$node}; } else { print "Node $node not found in HoH\n"; } } # Loop over remaining unmatched keys for my $key (keys %HoH) { print "Key $key with payload $HoH{$key}->{day} not matched, so add +ed\n"; }

🦛


In reply to Re^11: Update XML Values using two primary keys by hippo
in thread Update XML Values using two primary keys by pratikpooja

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.