any simple way to do this?

R

robertchen117

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.
 
S

Sisyphus

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";
 
P

Paul Lalli

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
 
S

Sisyphus

..
..
^^

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top