0

I am new to Perl

<nst:root arg='1' arg2='2' arg3='3'>
   <a>1</a>
   <b>2</b>
</nst:root>

I want 2 variable like,

$root = '<nst:root arg='1' arg2='2' arg3='3'>';
$rootClose = '</nst:root>';

I want a regular expression for this. Because I can not read line by line. My xml file can be like below also

<nst:root arg='1' arg2='2' arg3='3'><a>1</a><b>2</b></nst:root>

I don't want to read a full file. Because I have 100's of file and one file contains more than 10k line.

Sahal
  • 4,046
  • 15
  • 42
  • 68

1 Answers1

1

Try this

open(my $fh,"<your file name");
while(<$fh>){
   $test=$_;
   if ($test =~ /([^>]*)>.*<([^>]*)/g) {
      print qq{$1>  <$2>};
   }
last;
}
Noble
  • 77
  • 7
  • Thanks, my aim is to update one xml file with other xml. Please help – Sahal Nov 05 '13 at 10:13
  • Example, I want to update the root tag `` with `` – Sahal Nov 05 '13 at 10:14
  • See this is what I wanted to do. I have an xml file and that has actual root tag. I split that file in to multiple using XML::Twig::xml_split. I get many files but header is different. I want to update the child file with actual header from mail file. – Sahal Nov 05 '13 at 10:17
  • You should have said so in the first place. – simbabque Nov 05 '13 at 11:05