The short answer is take rob_au's (s)printf recommendation. The whole scalar is-a scalar is-a scalar (i.e., integer <=> float <=> string) thing has probably bitten all of us at one point or another. (s)printf can go a long way toward setting things right, when nothing else seems to work.

Be aware that, if you use CGI.pm to retrieve your script's parameters, the value returned by param() will be precisely what the user entered, warts (leading zeroes) and all. It is what happens after this point that determines whether (and when) Perl begins to treat your string of digits as a number. Sometimes it helps to step through the code with the perl debugger to see where things change.

(For a CGI script, you can obtain an appropriate command line for the debugger from your browser by changing the form's retrieval METHOD to GET, instead of POST. Then, after submitting your form, go to your browser's location bar and copy everything after the question mark (as in, http://your.server.domain/path/mycgiscript.cgi?...), not including the question mark istelf, and paste it onto the end of a command line at the prompt, so that it looks something like this: perl -d mycgiscript.cgi param1=val1&param2=val2. Then step through the script to the location of the problem. Remember, you're not necessarily interested in *debugging* the script--although it's possible--but rather in determining at when and why a particular variable's value starts being treated as a numerical value.)

When dealing with strings that happen to look like numbers (e.g., zip codes), ensure that they are treated as strings by avoiding (deliberate or otherwise) numerical manipulations. You must be careful to examine what you do with the values subsequent to retrieving them; you may be implicitly forcing Perl to treat them as numbers (which is why dws asked to see your code).

It's important to do this analysis, because once your awareness of how/when/why Perl differentiates between numbers and strings reaches a critical mass, you may find yourself slapping your forehead, leaping up out of your chair and yelling, "Aha!"

Or maybe not.

If you cannot locate and correct where you might be (implicitly or otherwise) treating your fields as numbers, using one of sprintf or printf, to gather and format the three phone number fields into a single output value is perhaps a simpler solution.

dmm

You can give a man a fish and feed him for a day ...
Or, you can
teach him to fish and feed him for a lifetime

In reply to Re: Cgi Phone Number Problem by dmmiller2k
in thread Cgi Phone Number Problem by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.