ccherri has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: confirming key in xml?
by Anonymous Monk on Apr 06, 2015 at 21:30 UTC | |
by ccherri (Acolyte) on Apr 07, 2015 at 16:41 UTC | |
by ccherri (Acolyte) on Apr 07, 2015 at 16:49 UTC | |
by Lotus1 (Vicar) on Apr 07, 2015 at 18:46 UTC | |
|
Re: confirming key in xml?
by pme (Monsignor) on Apr 06, 2015 at 21:35 UTC | |
by Anonymous Monk on Apr 06, 2015 at 21:59 UTC | |
by Anonymous Monk on Apr 06, 2015 at 22:20 UTC | |
by pme (Monsignor) on Apr 06, 2015 at 22:54 UTC | |
by karlgoethebier (Abbot) on Apr 07, 2015 at 18:28 UTC | |
|
Re: confirming key in xml?
by Lotus1 (Vicar) on Apr 07, 2015 at 19:37 UTC | |
|
Re: confirming key in xml?
by locked_user sundialsvc4 (Abbot) on Apr 06, 2015 at 23:26 UTC |