#!/usr/bin/perl
print qq|<?xml version="1.0"?>|;
print "\n";
while($_=<DATA>){
my $save;
if (/^\{FILE\}/ .. /^\{NUMBER\}/) {
unless (/^\{(FILE|NUMBER)\}/) {
my $filename = $_;
print "The filename is $filename\n";
}
}
open FH,">$filename.xml";
print FH '<?xml version="1.0"?>';
print FH "\n";
$_ =~ s/[\cA-\cZ]//g;
if ( /^{(\w+)}/ ... /^\w+/ ) {
my $tag = $1 if $1;
if( ! /^{/ ){
print FH "<$tag>$_</$tag>\n";
# print FH "<\$tag\>$_\</$tag\>\n";
}
}
}
close FH;
__DATA__
^B^B^B^B^B^B
{FILE}
sourcetag1
{NUMBER}
00000
{SOURCE}
source1
{KEYWORD}
{AUTHOR}
author
staff
{FILE}
sourcetag2
{NUMBER}
00001
{SOURCE}
sourcenam
{KEYWORD}
{AUTHOR}
author1
staff1
The contents from {FILE} should be the filename.
Here I have used the filename as sourcetag1.
But file contains '?' in the filename and contents of
print FH "<$tag>$_</$tag>\n";
is not written to a file.
The content should write to the file until another {FILE} is read.
When {FILE} is read the file should be closed and another file should be opened with the value as sourcetag2
Can you please tell me why the contents are written to the file.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.