I modified my code .Its working thanks

Original node content restored below by GrandFather

I modified muy code .Its printing only heade and footer for each file not actual records.Can you please modify it. thanks

use strict; use warnings; my $source ="temp.txt"; my $num = 1; my $recline = 10; open(DATA,"<$source") or die "Can't open '$source' $!"; while (!eof DATA) { my $outfile=sprintf("Int_%s.txt",$num); ## Open the file +once every iteration open OUT, ">$outfile"; my $header = sprintf("%-1s%-12s%-8s%-4s%-4s%-10s%-33s","H" +,$outfile,"20101221","1230","$num","$recline"," "); print OUT $header ."\n"; ## Prints the header here ### Print the contents of the file here, the header is pri +nted above and trailer is printed below. #### for (1 .. $recline) { last if eof DATA; last if ! defined (my $line = <DATA>); print $line; } my $trailer = sprintf("%-1s%-12s%-8s%-4s%-4s%-10s%-33s","T +",$outfile,"20101221","1230","$num","$recline"," "); print OUT $trailer ."\n"; ## Prints the trailer here $num++ if ($. % $recline eq '0'); close (OUT); ## Close the file in the same iteration, so + that a new file is opened next iteration } close(DATA);

In reply to Re^2: split a file by chinni2010
in thread split a file by chinni2010

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.