I've been trying to figure out how to determine if a key (Voltage) exists in my xml file and finally settled on...

test.xml - <Settings ModelNumber="1" SerialNumber="13"> - <Channels> <Channel Name="FSC" Voltage="12" Threshold="15" /> <Channel Name="SSC" Voltage="10" Threshold="20" /> </Channels> - <Pods> </Pods> </Settings> use XML::Simple; $inst_set= XMLin($file); foreach my $Channel(@{$inst_set->{Channels}->{Channel}}){ if($Channel->{Voltage}){$settings_file=$file} #if the Voltage exis +ts, it must be the settings file } }

This works, i just KNOW this is not an elegant solution, and therefore probably not the most reliable, so looking for some feedback. Having made this work, now need to change the Voltage value in the original xml. Has anyone got recommendation on best module to use to modify the original file? Thanks Chris


In reply to confirming key in xml? by ccherri

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.