#!/usr/bin/perl use strict; use warnings; my $fh; my $tag; while(<DATA>){ chomp $_; $_ =~ s/[\cA-\cZ]//g; #$_ =~ s/^\s+$//g; #$_ =~ s/\n//g; #$_=~ s/[\r]//gs; if(/^{(.*)}/) { $tag = $1; print $tag."\n";; } else { if($tag eq 'FILE') { my $filename = $_; # print "The filename is $filename\n"; open($fh, '>', "$filename.xml") or die "$filename: $!"; print $fh '<?xml version="1.0"?>',"\n"; print $fh "<root>\n"; print $fh "<FILE>$filename</FILE>"; } elsif(defined($fh)) { if( $_ ne ''){ #### Remove the blnak lines chomp $_; print $fh "<$tag>$_</$tag>\n"; } #print $fh "</root>"; } } } close($fh); exit(0); __DATA__ ^B^B^B^B^B^B {FILE} sourcetag1 {NUMBER} 00000 {SOURCE} source1 {KEYWORD} {AUTHOR} author1 staff1 {HEADLINE} DISPOSABLE DECOR: THE CUTTING EDGE DULLS FAST\ STYLE AT A SPEED USUALLY ASSOCIATED WITH WARDROBE ITEMS. {FILE} sourcetag2 {NUMBER} 00002 {SOURCE} sourcenam2 {KEYWORD} {AUTHOR} author2 staff2
Please can you tell me why the output in sourcetag1.xml is displayed as below:
<?xml version="1.0"?> <root> <FILE>sourcetag1</FILE><NUMBER>00000</NUMBER> <SOURCE>source1</SOURCE> <AUTHOR>author1</AUTHOR> <AUTHOR>staff1</AUTHOR> <HEADLINE>DISPOSABLE DECOR: THE CUTTING EDGE DULLS FAST\</HEADLINE> <HEADLINE>STYLE AT A SPEED</HEADLINE> <HEADLINE>USUALLY ASSOCIATED WITH WARDROBE ITEMS.</HEADLINE>
The <HEADLINE> is repeated 3 times

In reply to Re^2: Writing to a file by Anonymous Monk
in thread Writing to a file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.