Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   any simple way to do this? (http://www.velocityreviews.com/forums/t902610-any-simple-way-to-do-this.html)

robertchen117@gmail.com 04-09-2007 08:59 AM

any simple way to do this?
 
the day of the date is a number, April 4.

I want to replace the number with 04, if it is already 04, then do
nothing. If it is 4 replace with 04.

Please give me a simple way to do this.


Sisyphus 04-09-2007 09:44 AM

Re: any simple way to do this?
 

<robertchen117@gmail.com> wrote in message
news:1176109192.851005.41220@n59g2000hsh.googlegro ups.com...
> the day of the date is a number, April 4.
>
> I want to replace the number with 04, if it is already 04, then do
> nothing. If it is 4 replace with 04.
>
> Please give me a simple way to do this.
>


Does this help ?

---------------
use strict;
use warnings;

for(04, 4, 14, 214) {printf "%02d ", $_}

print "\n";

#or use sprintf() if you want to assign:

for(04, 4, 24, 4132) {
my $formatted = sprintf( "%02d", $_);
print $formatted, " ";
}

print "\n";
------------------

Cheers,
Rob


Paul Lalli 04-09-2007 01:20 PM

Re: any simple way to do this?
 
On Apr 9, 5:44 am, "Sisyphus" <sisyph...@nomail.afraid.org> wrote:
> <robertchen...@gmail.com> wrote in message
>
> news:1176109192.851005.41220@n59g2000hsh.googlegro ups.com...
>
> > the day of the date is a number, April 4.

>
> > I want to replace the number with 04, if it is already 04, then do
> > nothing. If it is 4 replace with 04.

>
> > Please give me a simple way to do this.

>
> Does this help ?
>
> ---------------
> use strict;
> use warnings;
>
> for(04, 4, 14, 214) {printf "%02d ", $_}
>
> print "\n";
>
> #or use sprintf() if you want to assign:
>
> for(04, 4, 24, 4132) {

^^

Be careful. That worked only because Decimal 4 happens to be
equivalent to Octal 4. Try it with 09 or 010 and see what happens.

Paul Lalli




Sisyphus 04-10-2007 01:36 AM

Re: any simple way to do this?
 

"Paul Lalli" <mritty@gmail.com> wrote in message
..
..
>> for(04, 4, 24, 4132) {

> ^^
>
> Be careful. That worked only because Decimal 4 happens to be
> equivalent to Octal 4. Try it with 09 or 010 and see what happens.
>


Damned octal :-)

s/04/'09'/

Cheers,
Rob


All times are GMT. The time now is 11:36 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.