Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Adding Leading Zeros

by Anonymous Monk
on Aug 29, 2016 at 17:27 UTC ( [id://1170719]=note: print w/replies, xml ) Need Help??


in reply to Adding Leading Zeros

Simple trick with perl. use strings instead of numbers:

    foreach my $index ('00'..'12') {
vs
    foreach my $index (00..12) {

Replies are listed 'Best First'.
Re^2: Adding Leading Zeros
by Anonymous Monk on Aug 29, 2016 at 18:28 UTC

    Oh! You must mean some like this:

    my @inputs = (20188, 18350, 4005, 127736, 10291, 4937, 57500, 150494); sub with_zeroes { grep( $_ == $_[0], '0000000000' .. '9999999999' ) } say with_zeroes($_) for @inputs;
    Small doubt about efficiency remains however.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-19 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found