Hi perlmonks,

I would like to create a file and write the information in a proper position in a file. The below code is working fine, but I am looking for a good code.

The iput data is under __DATA__ section
my requirement is to write first value starting from position 1 to 10, second value should start from 11th position to 17th and third should start from 18th to 25th position.

Can anyone please help to write a good code in perl.

open(A,">Result.txt"); while(<DATA>) { my($one,$two,$three)= split(/\s+/,$_); my $delim=' '; my $one1=length($one); my $two1=length($two); my $three1=length($three); my($one2,$two2,$three2); if($one1 < 10) { my $one11= (10-$one1); my $fdelim=$delim x $one11; $one2=$one.$fdelim; } if($two1 < 7) { my $two11= (7-$two1); my $fdelim=$delim x $two11; $two2=$two.$fdelim; } if($three1 < 8) { my $three11= (8-$three1); my $fdelim=$delim x $three11; $three2=$three.$fdelim; } print A "${one2}${two2}${three2}\n"; } close(A) __DATA__ The Early Year Five New Swine

Thanks

In reply to File Formatting - Help required by Anonymous Monk

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.