Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Dropping Leading Zeros

by Anonymous Monk
on Feb 05, 2002 at 14:50 UTC ( [id://143447]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

First i think those that tried to help me before but printf is not appropriate for this matter. I am using a home made templaeing system. Mainly stripping out $bunny and replacing with the database value of bunny. I dump the html template file into a scalar and string replace all the the occurances of $bunny with the value. Zip codes and phone number get their leading zeros truncated. I do not want to if at all possible add "O" to the front of things. And printf won't work since at the end I am printing the entire scalar ( web page ) to the screen. What do I do? I am at a loss for a solution. If you want more information I can be e-mailed at dragonwindstorm@angelfire.com Please help me if you can

Replies are listed 'Best First'.
Re: Dropping Leading Zeros
by Chady (Priest) on Feb 05, 2002 at 15:05 UTC

    so how about sprintf?

    and some code?


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/
Re: Dropping Leading Zeros
by gellyfish (Monsignor) on Feb 05, 2002 at 15:02 UTC

    A scalar should only lose the leading zeroes if you have attempted to treat it as a number somewhere along the line - and its a bit difficult to diagnose this as you don't show any code. Is it possible that you are doing something like adding zero to it or whatever >

    /J\

Re: Dropping Leading Zeros
by Parham (Friar) on Feb 05, 2002 at 23:57 UTC
    i couldn't quite understand the question... but from the title of the post.. you want to remove leading zeros
    $number = '00000000000005341390432'; $number =~ s/^0+//; print $number;
    would output: 5341390432
      i couldn't quite understand the question... but from the title of the post.. you want to remove leading zeros

      On the contrary, in his case, his program drops zeros that should be kept (zip codes, phone numbers). Your answer is valid, but off-topic. Yet, I did not downvote you, you wanted to help.

      Back to the question. I think that the real problem is that in the database, phone numbers and zip codes are described as numbers, and this is wrong. Phone numbers are strings, not numbers (consider 1-800-COLLECT), and zip codes are strings, not numbers (consider British and Canadian zip codes). Like gellyfish said, a few lines of code would help (do not post your whole program, yet, just select the few lines in question).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-24 09:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found