in reply to Cgi Phone Number Problem

This is a hack, but if you check the length of the field and it's too short, prepend a zero:
while ( length $field2 < 4 ) { $field2 = "0" . $field2; }
Update
Keep in mind that by doing this you can, for instance, add to $field2, and still keep the leading zero. Since I'm new, at least comment on why this node is bad...

Replies are listed 'Best First'.
Re: Re: Cgi Phone Number Problem
by MZSanford (Curate) on Jan 07, 2002 at 14:20 UTC
    You asked "comment on why this node is bad...", and i think it would help you to know. From what i can tell, the reason people might down vote this is because perl has a set of internal functions which do the same thing much faster. sprintf and printf. The post prior to yours points this out. While i am sure most of us at some point have written code similar to yours, i imagine people down-voted it because the post prior haad a faster, cleaner solution. Don't let this discourage you ... read up on (s)printf for the next time ... this is how we all learn it.
    $ perl -e 'do() || ! do() ;' Undefined subroutine &main::try
      Thanks, that's just what I was looking for. I have never used sprintf outside of C, and had not even thought of it in perl. I don't mind the '-' vote as much as not knowing why... Thanks.