Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^3: Left padding a number with zeros: PerlFaq method didn't work for me.

by ChemBoy (Priest)
on Jan 17, 2006 at 04:45 UTC ( #523665=note: print w/replies, xml ) Need Help??

in reply to Re^2: Left padding a number with zeros: PerlFaq method didn't work for me.
in thread Left padding a number with zeros: PerlFaq method didn't work for me.

You were probably only one character away at one point...unfortunately, then you jumped the wrong direction. :-) The format you were looking for is "%04d", which is equivalent to the version in perlfaq4 if $padlen is equal to 4.

Your mistake was that you replaced the string "pad_len" with an integer, rather than replacing the variable $pad_len (which is inserted in the string in the FAQ using braces so that perl knows you're not looking for the variable $pad_lend). Since this means that instead of inserting "4" into your string, you're inserting the value of $4, which happens to be empty, you get no padding, which I presume is the error you saw.

If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://523665]
[shmem]: holli: all of our machinery is more perfect in its realm than any human being in theirs (Günther Anders), which doesn't mean not having fun, albeit dangerous sometimes.
[ww]: That's a big "if", holli.
[holli]: well the google car drove 5 times as far as the average human without an accident didnt it?
[ww]: Less than confident that ai+hardware is up (yet) to randomness and counterintuitive behavior on streets of NY
[ww]: (and having lived both, Boston traffic challenges are even >.
[holli]: the nice thing about ai is that if it had an accident, it can learn and never do the same mistake again

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2017-11-21 13:18 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (301 votes). Check out past polls.