Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
How to write $_, inside the tag until it finds the string in an array.#!/usr/bin/perl use strict; use warnings; my $fh; my $tag; while(<DATA>){ chomp $_; if(/^{(.*)}/) { $tag = $1; push(my @metadata_tags,$tag); } else { if($tag eq 'FILE') { if(defined($fh)){ print $fh "</ROOT>"; close($fh); } my $filename = $_; open($fh, '>', "$filename.xml") or die "$filename: $!"; print $fh '<?xml version="1.0"?>',"\n"; print $fh "<ROOT>\n"; print $fh "<FILE>$filename</FILE>\n"; } elsif(defined($fh)) { if($_ ne ''){ #### Remove the blnak lines print $fh "<$tag>$_</$tag>\n"; } } } } exit(0); __DATA__ {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
print $fh "<$tag>$_</$tag>\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Read the lines until a string exists in the array
by rovf (Priest) on Aug 14, 2009 at 07:45 UTC | |
by Anonymous Monk on Aug 14, 2009 at 08:20 UTC | |
by rovf (Priest) on Aug 14, 2009 at 09:21 UTC | |
by Anonymous Monk on Aug 14, 2009 at 09:27 UTC | |
by rovf (Priest) on Aug 14, 2009 at 09:47 UTC | |
|