And my comments are this: run this code and ask questions :)
What this code essentially does is pull out things that look like phone numbers from each line. Then removes non-digits and checks the length of what is left. Based on that length, you can determine whether you need to add your default area code (333) and/or the default extension (321). Then you format the final number and substitute that back into your original line.use strict; use warnings; my( $area_code, $extension ) = ( 333, 321 ); while (<DATA>) { my ($number) = $_ =~ /\s([0-9()-]+)/; $number =~ s/\D//g; if (length( $number ) == 4) { $number = $area_code . $extension . $number; } elsif (length( $number ) == 7) { $number = $area_code . $number; } elsif (length( $number ) == 10) { # do nothing } else { warn "could not parse $number\n"; next; } $number =~ s/(\d{3})(\d{3})(\d{4})/($1)-$2-$3/; $_ =~ s/([0-9()-]+)/$number/; print; } __DATA__ Black, Joe 0987 Smith, Sue 0534 Brown, Andy 587-0986 Smith, Pam (615)-895-1010
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to Re: total noob trying to format a phone list
by jeffa
in thread trying to format a list
by sonikd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |