in reply to File write problem

perl_seeker:

You should read the documentation for printf/sprintf. It's unreasonable for you to expect that it will magically interpolate the variables into their values for the desired width. You need to tell it the width you want. For example:

printf "%-15.15s % 4d\n", $string, $integer;

This code tells printf to format the $string variable into a 15 character column, left justifying it (and truncating it if it's too long. It formats $integer into a 4 character field, filling with spaces.

...roboticus

Update: Cleaned up the formatting. (Thanks, moritz!)

Replies are listed 'Best First'.
Re^2: File write problem
by perl_seeker (Scribe) on Aug 03, 2010 at 12:05 UTC
    Hello, it was whitespace characters causing everything after the Qty figure to appear on the second line.
    Don't know why the code did not work earlier. Fixed the second line prob using this
    open PL, 'pvclength.txt' or die "Cant open file"; $pvc_l=<PL>; $pvc_l =~ s/^\s+//; $pvc_l =~ s/\s+$//;
    Also for the alignment will look up on sprintf. Thank you everyone for your comments and sorry for the delay in
    replying.

    perl_seeker