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?
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:
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.Code:zero_fill($text,13)
I'm a little confused. Do I put the function at the top and then:
?Code:zero_fill("108",4")
You put the function wheverever you want to in your script. It really does not matter.
Cool, got it working right after I made that last post and never responded back. Thanks for your help.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks