Perhaps the following will give you some ideas you can use:
use strict; use warnings; my $fh; my $tag; while(<DATA>){ chomp; if(/^{(.*)}/) { $tag = $1; } else { if($tag eq 'FILE') { my $filename = $_; print "The filename is $filename\n"; open($fh, '>', $filename) or die "$filename: $!"; print $fh '<?xml version="1.0"?>',"\n"; } elsif(defined($fh)) { print $fh "<$tag>$_</$tag>\n"; } } } close($fh); exit(0); __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
In reply to Re: Writing to a file
by ig
in thread Writing to a file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |