Hi All, Im currently working on perl script that will covert the content on a given pattern. I want to make my code dynamic so I used the sub routine function so that it can handle the multiple patterns to be converted.
Since per data it has an inconsistent Heading 2 content.
Ex.
<Heading 2>General No. 1289
<Heading 2>SRL Nos. 1312 & 1294
it should have an output of GeneralNo.1289 and SRLNos1312 _1294
Does the use of my subroutines are correct?
And Does the flagging of varibles are correct in my codes below?
I'm new to perl and I'll really appreciate your help to correct my errors below.
Thank You!
#!/usr/bin/perl
use warnings;
$input_data = @ARGV[0];
$output_data = @ARGV[1];
$h2_flag = 0;
$h3_flag = 0;
open(INFILE,"$input_data") || die "cannot open input file : $infile";
open(OUTFILE,">$output_data") || die "cannot open temporary output fil
+e : $output_data";
$/=undef;
# Process error data to rectify the error records in massaged data
while (<INFILE>) {
$data = $1;
if ($data =~ m/(<RD,ID:[A-Z0-9]*:"Heading\s*2">.*)/) {
$h2_flag++;
}elsif ($data =~ m/(<RD,ID:[A-Z0-9]*:"Heading\s*3">.*)/) {
$h3_flag++;
}
if ($h2_flag == 1) {
if ($data =~ m/(<RD,ID:[A-Z0-9]*:"Heading\s*2">.*)/) {
$head_data = $1;
$head_data =~ s/<RD,ID:[A-Z0-9]*:/<RD:/gi;
}
}
&heading;
sub heading{
if ($h2_flag == 1) {
if ($data = m/(<RD,ID:[A-Z0-9]*:"Heading\s*2">.*)/) {
$head_data = $1;
$Case_No = $head_data = s/(<.*>)(.*)/$2/;
$Case_No = $head_data;
$date = $head_data;
$h2_flag = 0;
}elsif ($h3_flag == 1) {
print "PRINT";
$h3_flag = 0;
}
}
print OUTFILE $_; # Output the contents of $_ t
+o
# output file
}
# Close the INFILE and OUTFILE.
close(INFILE);
close(OUTFILE);
Hi,
This is the sample of the data:
<DR:"Heading 2">T.G No. L-5786 December 29, 2010
<DR:"Heading 3">ASIAN vs. ET AL.
Sample output on should be all special character will be remove.
and the date will be converted as 12292010.
Output:
<Head>TGNL5786Y12292010
Description:
TGNL5786 - Head
Y - Consistent Indicator of date.
Date - 12292010
December will be 12
Date is 29 and Year is 2010.
the month word will always be converted into its numeric value. Januar
+y - 01