Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > Perl

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

Perl Discussion for the PERL language - Practical Extraction and Reporting Language, is a programming language often used for creating CGI programs.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-29-2007, 11:32 AM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Credits: 0
Rep Power: 12
NeedHelp is on a distinguished road
Default Remove Leading 0's

I've been tasked with another "fix" which seems simple but isn't (to me). I need to remove all leading 0s of a string:

"00000002035"

needs to be

" 2035"

Is there some function I can use to do this already? The spacing needs to remain the same though.
__________________
I Need Help

Last edited by NeedHelp; 03-29-2007 at 11:33 AM. Reason: Forgot to mention
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-29-2007, 11:49 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 3,205
Last Blog:
Passwords
Credits: 842
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default

you should be able to use regex
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-29-2007, 12:00 PM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Credits: 0
Rep Power: 12
NeedHelp is on a distinguished road
Default

I found this:

Perl Reference

which lead me to making this:

Code:
$mystring =~ s/^0*//;
$mystring =  sprintf("%- 18s", $mystring);
And does what I need. Is this the best method though?
__________________
I Need Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-29-2007, 03:01 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 3,205
Last Blog:
Passwords
Credits: 842
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default

I don't know anything about perl so I cant tell you if thats the BEST way to do it. From my little understanding of regular expressions, it 'looks good.'

My theory is, if it works leave it alone
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-29-2007, 07:19 PM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 89
Credits: 0
Rep Power: 7
KevinADC is on a distinguished road
Default

Quote:
Originally Posted by NeedHelp View Post
I found this:

Perl Reference

which lead me to making this:

Code:
$mystring =~ s/^0*//;
$mystring =  sprintf("%- 18s", $mystring);
And does what I need. Is this the best method though?
Yes, that is a good way to do what you want.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-05-2007, 03:35 PM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Credits: 0
Rep Power: 12
NeedHelp is on a distinguished road
Default

Thanks for the input. This method seems to be working fine for now.
__________________
I Need Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-16-2007, 10:53 AM
ghostdog74 ghostdog74 is offline
Newbie
 
Join Date: Apr 2007
Posts: 6
Credits: 0
Rep Power: 0
ghostdog74 is on a distinguished road
Default

some other ways:
Code:
$new = sprintf "%d" , "000023";
print $new;
Code:
$val = "00032";
$new = int $val; 
print $new;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-16-2007, 01:09 PM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Credits: 0
Rep Power: 12
NeedHelp is on a distinguished road
Default

I never thought of the int $val method. That would work fine I would think.
__________________
I Need Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to remove your second XP without formating - [With Video] Onur Tutorials 1 08-31-2007 07:42 AM
Remove Autofill in FF falco85 JavaScript and CSS 1 07-04-2007 10:19 AM
Tutorial to Remove the Virus "Trojan horse Startpage.ADE" clookid Tutorials 9 01-09-2007 09:39 PM


All times are GMT -5. The time now is 04:51 AM.

Contest Stats

Xav ........ 1024.41
MeTh0Dz|Reb0rn ........ 974.08
morefood2001 ........ 850.04
John ........ 841.93
WingedPanther ........ 661.52
marwex89 ........ 575.59
Brandon W ........ 456.18
chili5 ........ 292.12
orjan ........ 187.41
Steve.L ........ 181.88

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 79%

Ads