Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > Perl

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 01-19-2007, 02:06 PM
Cosmet Cosmet is offline
Learning Programmer
 
Join Date: Oct 2006
Posts: 58
Rep Power: 8
Cosmet is on a distinguished road
Default Left Fill in Perl?

How can I pad left in perl? Basically if I have a string like

108

I need to fill 4 spaces in front of it with 0's. IE

0000108

Is this possible in Perl?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 01-22-2007, 04:23 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,228
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

Here is some code I used before:

Function:

Code:
# Pad-Left 0's Function
# Takes two parameters - Variable and number of 0s
sub zero_fill
{
    $pad_len = $_[1] - length($_[0]);
    $padded = sprintf("%0${pad_len}d", $_[0]);
    print "$padded\r\n";
    return $padded
}

Call it like:

Code:
zero_fill($text,13)
Where $text is what you want to be padded left and 13 is the amount of 0's you want it to pad left by.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-24-2007, 02:59 PM
Cosmet Cosmet is offline
Learning Programmer
 
Join Date: Oct 2006
Posts: 58
Rep Power: 8
Cosmet is on a distinguished road
Default

I'm a little confused. Do I put the function at the top and then:

Code:
zero_fill("108",4")
?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-29-2007, 02:22 AM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 91
Rep Power: 7
KevinADC is on a distinguished road
Default

You put the function wheverever you want to in your script. It really does not matter.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-12-2007, 07:19 PM
Cosmet Cosmet is offline
Learning Programmer
 
Join Date: Oct 2006
Posts: 58
Rep Power: 8
Cosmet is on a distinguished road
Default

Cool, got it working right after I made that last post and never responded back. Thanks for your help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: Disk Space Jordan Tutorials 16 10-17-2008 03:57 PM
printing out into notepad from the html using perl lichy Perl 8 12-14-2007 02:06 PM
Perl is Dead. Long live Perl. Kernel Programming News 3 08-10-2007 11:49 AM
Move a file in Perl Cosmet Perl 3 02-12-2007 11:43 PM
Perl Tutorial Course for Windows priorityone Perl 22 02-11-2007 01:57 AM


All times are GMT -5. The time now is 04:17 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads