0

... so after I replace a with b, all previous references to a now point to b?

ZzZombo
  • 1,082
  • 1
  • 11
  • 26

1 Answers1

2
#!/usr/bin/perl
use warnings;
use strict;

use XML::LibXML;

my $dom = 'XML::LibXML'->load_xml(string => '<r><p><c/></p></r>');
my ($n1) = $dom->findnodes('/r/p/c');
my ($n2) = $dom->findnodes('/r/p/c');
$n1->replaceNode('XML::LibXML::Element'->new('n'));
print $dom;
print $n1, $n2;

Output:

<?xml version="1.0"?>
<r><p><n/></p></r>
<c/><c/>
choroba
  • 231,213
  • 25
  • 204
  • 289
  • Why do you have quotes around your package names? – simbabque Nov 08 '16 at 13:57
  • 1
    @simbabque: Because http://www.perlmonks.org/?node_id=980498 and `::->` is too ugly to type. – choroba Nov 08 '16 at 14:31
  • @simbabque, They're protecting themselves against the remote possibility that there's a sub called `XML::LibXML`. Perl actually allows you to do use `XML::LibXML::` to solve that problem. – ikegami Nov 08 '16 at 16:21