Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Is There A Better Way?

by simeon2000 (Monk)
on Aug 13, 2002 at 15:12 UTC ( [id://189821]=note: print w/replies, xml ) Need Help??


in reply to Is There A Better Way?

sprintf is great for formatting numbers.

$input = sprintf("%011d", $input);

That oughtta do the trick.

--
perl -e "print qq/just another perl hacker who doesn't grok japh\n/"
simeon2000|http://holdren.net/

Replies are listed 'Best First'.
Re: Re: Is There A Better Way?
by simeon2000 (Monk) on Aug 13, 2002 at 15:47 UTC
    And since there's more than one way to do it...

    $num = 12; print 0 x (11 - length($num)), $num;

      And some more obfuscated ways listed in this thread - Including my own attempt at obscurity ...

      sub a{$_=int$_[0]*10**$_[1]+.5;s;(.{$_[1]})$;\.$1;;chop if substr($_,- +1)eq'.';return$_};
      ... Although I would not use it in production code myself :-)

       

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://189821]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2024-04-19 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found