in reply to Re^2: Splitting XML file on Processing Instructions
in thread Splitting XML file on Processing Instructions
No problem. This just requires that the <no>...</no> tags are put in an array. But we use $numbers[-1] instead of $numbers[$#numbers].
#! /usr/bin/perl -w use strict; my $text; if (open INPUT, '<data') { local $/; $text = <INPUT>; close INPUT; } while ($text =~ /<\?split \?>(.*?)(?=<\?split \?>)/sg) { my $fragment = $1; my ($h1) = $fragment =~ /<h1>(.*?)<\/h1>/is; my @numbers = $fragment =~ /<no>(.*?)<\/no>/isg; if (open OUTPUT, ">${h1}-nr${numbers[0]}to${numbers[0-1}.xml") { print OUTPUT $fragment; close OUTPUT; } } exit 0;
|
|---|