in reply to How do I delete a specific element from an XML file

That's what supposed to happen. If you do a Data::Dumper of $category, you will see that $category->{'subcategory'}[$countersubs]{'product'}[$counterprod]{'channel'} is a hash element that contains an array ref.

delete $category->{'subcategory'}[$countersubs]{'product'}[$counterpro +d]{'channel'}[counterchan]

deletes the counterchan th element of the array. (I think "counterchan" is a typo of "$counterchan")

delete $category->{'subcategory'}[$countersubs]{'product'}[$counterpro +d]{'channel'}

deletes the hash element, which is the entire array.

Replies are listed 'Best First'.
Re^2: How do I delete a specific element from an XML file
by pg (Canon) on Oct 31, 2004 at 03:50 UTC

    A side note: delete an array element does not shift index. Try the following example:

    use Data::Dumper; use strict; use warnings; my @a = (1,2,3,4,5); print Dumper(\@a); delete $a[1]; #splice(@a, 1,1); print Dumper(\@a);

    It gives you:

    $VAR1 = [ 1, 2, 3, 4, 5 ]; $VAR1 = [ 1, undef, 3, 4, 5 ];

    The array after deletion does not become something like

    $VAR1 = [ 1, 3, 4, 5 ];

    as splice does.

      Sorry about the spelling mistake I made for $counterchan. I understand in general what you said with the example but how do I implemented?
      I found the problem, it come from with the exit command. WIth this it works well
      delete $category->{'subcategory'}[$countersubs]{'product'}[$counterpro +d]{'channel'}[$counterchan]
      only when all loops is finished their process.
      Probem solve! Just need to put the command "exit 1" outside of the loop with a condition and everything works welll.
      Example:exit 1 if isDel;