Mornin' Sooraj,

As is true of most "does this work in Perl" questions, the answer is "Try it" --

C:\Documents and Settings\Administrator>perl -e
"$version=9;$version=sprintf(\"0%d\",$version); print $version; "
09
C:\Documents and Settings\Administrator>

Enjoy ---


B

On Wed, Aug 4, 2010 at 4:57 PM, Shawn H Corey <shawnhco...@gmail.com> wrote:
> On 10-08-04 05:39 AM, Sooraj S wrote:
>>
>> Hi,
>>
>> My code is accepting an option "version" as  an integer. If it is less
>> than 100, i need to add a zero in front of it so that i can do the
>> further processing.
>>
>> Although this code is working, i am not sure that its the proper way.
>> if ($version<  100)
>> {
>>     # convert an integer-variable to string.
>>     $version = sprintf("0%d",$version);
>> }
>>
>> I dont want to use something like my $str = sprintf("0%d",$version); I
>> want to have it in the same variable "version".
>>
>>
>
> Try:
>
> $version = sprintf( '%03d', $version );
>
> See `perldoc -f sprinf`
>
>
> --
> Just my 0.00000002 million dollars worth,
>  Shawn
>
> Programming is as much about organization and communication
> as it is about coding.
>
> The secret to great software:  Fail early & often.
>
> Eliminate software piracy:  use only FLOSS.
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>



-- 

Bob Goolsby
bob.gool...@gmail.com

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to