The problem you are seeing with
chomp is that Perl uses
the line terminator appropriate to the current platform, so if you're in UNIX, Perl chomps just the LF, which is the UNIX value of \n. If you had used the chomp in Win32 you would have removed CRLF, as that is the \n value for that platform. I presume (and welcome corrections) that if your phone data had come from a Mac, the UNIX chomp would not have removed anything, as for UNIX the lines would not appear to have terminators at all (and so the data would have been one long line). This is nicely described in
perlport.
As to fixing it, while chomp appears to be a logical choice, it is an approach of "remove the bad" when you believe you know what the bad is, but as this case has shown you often can't be certain of what the bad is. It is probably safer to
reverse this to an approach of "keep the good", with something like tr/0-9//cd, especially since your phone number field is so easy to specify.
--
I'd like to be able to assign to an luser
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.