hakana has asked for the wisdom of the Perl Monks concerning the following question:

Hello (again) Having problem with my xml-parsing. I want to add some data to my xml-file and everything works fine the first time but not the second time.
xml-file: <exec> <tc id="001.001" /> <tc id="002.001" /> <tc id="004.001" /> <tc id="005.001" /> <tc id="006.001" /> <tc id="007.001" /> <tc id="008.001" /> <tc id="009.001" /> </exec> perl-code: my $xmlfile = new XML::Simple (Outputfile => $conf, ForceArray => 1, Keyattr => 'id', RootName=>'exec'); my $xml = $xmlfile->XMLin($conf); $xml->{'dut'}->{'ipaddress'} = "$ipaddress"; $xml->{'dut'}->{'macaddress'} = "$Macaddress"; $xml->{'dut'}->{'model'} = "$ProdShortName"; $xml->{'dut'}->{'frimware'} = "$Firmware_Version";
The second time I get error messages like:
Pseudo-hashes are deprecated at ember.pl line 39. Argument "\x{31}\x{37}..." isn't numeric in hash element at ember.pl l +ine 39.
What is wrong?

Replies are listed 'Best First'.
Re: XML::Simple add
by Gangabass (Vicar) on Dec 14, 2007 at 09:50 UTC

    Your program doesn't have 39 lines. Please show real program.

    Also there is no need in double quotes. You can write just:

    $xml->{'dut'}->{'model'} = $ProdShortName;
Re: XML::Simple add
by Jenda (Abbot) on Dec 18, 2007 at 15:44 UTC

    Due to ForceArray=>1 the $xml->{'dut'} is an ARRAY ref, not a HASH ref! Therefore you should treat it as an array ref:

    push @{$xml->{dut}}, { ipaddress => $ipaddress, macaddress => $Macaddress, model => $ProdShortName, frimware => $Firmware_Version, # I think you mean firmware, not frim +ware };
    Try to print the $xml with Data::Dumper before you attemptto modify it to see how does the datastructure actually look.