By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,708 Members | 2,080 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,708 IT Pros & Developers. It's quick & easy.

Perl Regular Expression

P: 54
Hi,

I have a text file of 1,2,3,678,90, 100 as text.
i want to convert the number as three digit number in perl.
eg,
001
002
003
678
090
100
please help me

thanks,
murugavel
Dec 18 '08 #1
Share this Question
Share on Google+
1 Reply


KevinADC
Expert 2.5K+
P: 4,059
Next time please show some effort to solve your programming requirements. What you want is printf or sprintf.

Quick examples:

Expand|Select|Wrap|Line Numbers
  1. for (1,2,3,678,90,100) {
  2.    my $digits = sprintf ("%03d",$_);
  3.     print "$digits\n";
  4. }
  5.  
or:

Expand|Select|Wrap|Line Numbers
  1. for (1,2,3,678,90,100) {
  2.    printf ("%03d\n",$_);
  3. }
  4.  
Dec 18 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.