Dear Perl experts,
input file test.txt:
<table1><tgroup cols="3"></table1> <table2><tgroup cols="2"></table2>
output file test.out:
<table1><tgroup cols="3"> <colspec colnum='1' colname='1'/> <colspec colnum='2' colname='2'/> <colspec colnum='3' colname='3'/> </table1> <table2><tgroup cols="2"> <colspec colnum='1' colname='1'/> <colspec colnum='2' colname='2'/> </table2>
i want to print <colspec..> N number of times just after <tgroup cols="N"> depending upon the value N found inside <tgroup cols="N">.
But my following code prints the output outside somewhere
my %tval; open(IN, "<test.txt") || die "\nCan't open test.txt\n $!\n"; open(OUT, ">test.out") || die "\nCan't open test.out\n $!\n"; while(<IN>) { if(/<tgroup cols="(.*?)">/) { for ($count = 1; $count <= $1; $count++) { print OUT "<colspec colnum='$count' colname='$count'/>\n"; } } print OUT; } close(IN); close(OUT);
pls help me in fixing the code.

In reply to for loop by texuser74

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.