in reply to array/hash question with XML simple

Are you sure your $dat variable contains a number that corresponds to a valid array index for PAGE in the XML file?

Your code works for me:

Added:
use strict; use XML::Simple; my $docid = "pounces"; my $dat = $ARGV[0];

Used 2 files, both containing the same data so I could diff between runs. Both files had this content:

<opt version="1.0"> <page ui="gtk-gaim"> <account protocol="prpl">VinsWorldcom1</account> <actions> <action type="popup-notify" /> </actions> </page> <page ui="gtk-gaim"> <account protocol="prpl">VinsWorldcom2</account> <actions> <action type="popup-notify" /> </actions> </page> </opt>

Run on Windows ActiveState Perl v5.8.8:

{C} > 750398.pl 2 {C} > diff pounces.xml "Copy of pounces.xml" {C} > 750398.pl 1 {C} > diff pounces.xml "Copy of pounces.xml" 7a8,13 > <page ui="gtk-gaim"> > <account protocol="prpl">VinsWorldcom2</account> > <actions> > <action type="popup-notify" /> > </actions> > </page>

So you can see in the first run when I ask to delete "PAGE - 2" from the "2" as ARGV, nothing changes because there are only 2 PAGE array elements ([0] and 1). When I run it again as ask for 1, the second entry appears in the "COPY OF" file (as nothing happens to that file, it's my baseline), but it's deleted from the 'pounces.xml' file.

Replies are listed 'Best First'.
Re^2: array/hash question with XML simple
by TienLung (Acolyte) on Mar 13, 2009 at 13:54 UTC
    Many thanks for your help, Indeed $dat did contain the number. It now works as I wanted. What I believe was going wrong was that I was also calling the print command in various places, and with these print commands in place, it seems to stop working.
    my $pageobj=$data->{page}; print @$pageobj; delete $data->{page}[$dat]; print @$pageobj; my $xmlO = $xml->XMLout($data); open FILE, ">../services/xml/".$docid.".xml" or die; print FILE $xmlO; close FILE;
    This code does not work, but with the prints removed it does, so does calling print actually change the structure of the data structure? if so that would be good to know. Many thanks for your help, it working on yours meant I could focus my efforts away from thinking my syntax was wrong, and helped me find the real problem.