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

In reply to Manipulating a file by Siegfried13

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.