http://qs321.pair.com?node_id=774957

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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