Can't use an undefined value as a symbol reference at new.pl line 66,
+<DATA> line 4.
#!/usr/bin/perl
use strict;
use warnings;
my $tag;
my $output;
my $fh;
my $flag ='';
my $output_text;
my $i=0;
my $file='';
while (<DATA>) {
s/.*?\{IT\}/{IT}/g;
s/{IT}R/{IT}\nR/g;
chomp;
s/[\cA-\cZ]//g;
s/\^[A-Z]//g;
if(/^{(.*)}$/) # match {METATAG} line
{
$fh = xml_output($output, $tag, $fh,$i);
$output = "";
$tag = $1;
print "The tag is---->$tag\n\n";
}
else
{ # not a {TAG} line
next unless($tag);
next if(/^\s*$/);
$output .= ($output) ? " $_" : "<$tag>$_";
}
#
if($output =~ m/<IT>(.*)/){
$i++;
}
} # End of While Loop
$fh = xml_output($output, $tag, $fh,$i);
if($fh) {
print $fh "</ROOT>\n";
close($fh);
}
exit(0);
# Subroutine to open the file with the filename as {TAG}
sub xml_output {
my ($output, $tag, $fh,$i) = @_;
if($output) {
#print "The file name inside $file\n";
if($output =~ m/<IT>/) {
if($fh) {
print $fh "</ROOT>\n";
close($fh);
}
open($fh, '>', "$i.xml") or die "$1.xml: $!";
print $fh "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<RO
+OT>\n";
}
$output =~ s/\s*(?=(<.+>|<.+\/>|<\/.+>|<\/.+><.+>))//g;
print $fh "$output</$tag>\n";
}
return($fh);
} # End of sub sroutine
__DATA__
020200001117VUTVS01 00000745B3^V^V^A2^C^D^V^V^A 0000 0001 090104 N S00
+00000000 00001889^B{IT}R
{DATE}
090104
{TDATE}
Sunday, January 4, 2009
{SECTION}
H5
{HEADLINE}
LEGISLATORS VISIT SENIOR APARTMENT COMPLEX
{BODY}
2005 with state and federal funding. <
{IT}
R
{DATE}
050102
{TDATE}
Sunday, January 02, 2005
{EDITION}
6
{TAG}
0412270403
{BODY}
Certified Financial Planner for DiStefano Finacial Group in Westfield
+,
MA.
Can't use an undefined value as a symbol reference at new.pl line 66, <DATA> line 4.
I am getting an error.
I have added the code to delete strings before {IT}.
But still it gives out error message.
|