Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^5: remove line feed at the end

by ig (Vicar)
on Aug 15, 2009 at 16:27 UTC ( #788909=note: print w/replies, xml ) Need Help??

in reply to Re^4: remove line feed at the end
in thread remove line feed at the end

use strict; use warnings; my ($output, $tag, $fh); while (<DATA>) { chomp; s/^\s+//; s/\s+$//; if(/^{(.*)}$/) { # {TAG} line $fh = output($output, $tag, $fh); $output = ""; $tag = $1; } else { # not a {TAG} line next unless($tag); next if(/^\s*$/); s/\\//g; $output .= ($output) ? " $_" : "<$tag>$_"; } } $fh = output($output, $tag, $fh); if($fh) { print $fh "</ROOT>\n"; close($fh); } exit(0); sub output { my ($output, $tag, $fh) = @_; if($output) { if($output =~ m/<FILE>(.*)/) { if($fh) { print $fh "</ROOT>\n"; close($fh); } open($fh, '>', "$1.xml") or die "$1.xml: $!"; print $fh "<?xml version=\"1.0\"?>\n<ROOT>\n"; } print $fh "$output</$tag>\n"; } return($fh); } __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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://788909]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2018-03-20 08:47 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (248 votes). Check out past polls.