use strict;
use warnings;
my $XML = "";
while (<DATA>) {
chomp;
$XML .= "<line$.>$_</line$.>";
}
print join("",
'<?xml version="1.0">',
'<document>',
$XML,
'</document>'
);
__DATA__
param :PREFIX|numeric|sTAP|null
param :CLK_PERIOD|numeric|10000|null
param :STAP_NUMBER_OF_BITS_FOR_SLICE||16|null
param :STAP_SIZE_OF_EACH_INSTRUCTION|numeric|8|8-100
param :STAP_ENABLE_VERCODE|boolean|0
Note: I'm assuming your data doesn't include characters that need encoding. If it does, be sure to visit CPAN and get the appropriate encoding modules and encode the data before including it in your XML string.
Parsing XML into a hash has been beaten to death, so you can use search to find appropriate nodes. I could do it for you, but as others have mentioned, it's a bit far to go since you just want a hash. To convert to a hash directly would be simpler:
use strict;
use warnings;
use Data::Dumper;
my %Hash = ();
while (<DATA>) {
chomp;
$Hash{line$.} = $_;
}
print Dumper(\%Hash);
__DATA__
param :PREFIX|numeric|sTAP|null
param :CLK_PERIOD|numeric|10000|null
param :STAP_NUMBER_OF_BITS_FOR_SLICE||16|null
param :STAP_SIZE_OF_EACH_INSTRUCTION|numeric|8|8-100
param :STAP_ENABLE_VERCODE|boolean|0
Pretty easy, yes?
Of course, it's utterly useless, as I'm sure neither the XML document nor the hash are structured the way you want. But as you don't specify what you're looking for, and show no particular interest in doing it (as evidenced by the amount of effort shown), it at least fills the stated requirements...
Of course, the code is untested, so if there are any errors, you get to fix 'em.
</snarky-mode>
...roboticus
When your only tool is a hammer, all problems look like your thumb. |