Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > any simple way to do this?

Reply
Thread Tools

any simple way to do this?

 
 
robertchen117@gmail.com
Guest
Posts: n/a
 
      04-09-2007
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.

 
Reply With Quote
 
 
 
 
Sisyphus
Guest
Posts: n/a
 
      04-09-2007

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      04-09-2007
On Apr 9, 5:44 am, "Sisyphus" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) 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



 
Reply With Quote
 
Sisyphus
Guest
Posts: n/a
 
      04-10-2007

"Paul Lalli" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple way to go from xml to simple text format mathieu XML 3 01-06-2007 10:18 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
any simple way/command translating properties John_Woo Java 0 08-15-2006 05:59 PM
Any other way besides multiple frames to show absolute address? Simple question! gooderthanyou@gmail.com HTML 7 01-21-2006 12:58 AM
How to convert SVCD to DVD?? Does any know a simple way to do it? SJR2345 DVD Video 1 10-24-2003 02:38 AM



Advertisments