in reply to Re: issue with sprintf..
in thread issue with sprintf..

Max length of the variable will be zero. Even the variable is of length 5, I want to prefix '0's to make the length 11. Thats my intention.

Replies are listed 'Best First'.
Re^3: issue with sprintf..
by LanX (Saint) on Jan 09, 2014 at 10:38 UTC
    so better use sprintf properly, put a leading 0 in the pattern after %.

    Your s/ /0/ substitution is - politely said - less optimal. ;-)

    DB<117> $val=12143 => 12143 DB<118> sprintf("%011.0f", $val); => "00000012143" DB<119> $val=12143951645 => "12143951645" DB<120> sprintf("%011.0f", $val); => "12143951645"

    please read the documentation for more details. =)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      You mean to say I can remove that substitution s/ /0/ and simply use "sprintf("%011.0f", $val);" right?

Re^3: issue with sprintf..
by hdb (Monsignor) on Jan 09, 2014 at 10:45 UTC

    Or like this:

    $Val2 = '0' x (11-length $Val2) . $Val2 if length $Val2 < 11;

    or this

    $Val2 = substr "00000000000$Val2", -11;