sierrastar has asked for the wisdom of the Perl Monks concerning the following question:
the other portion of my problem is using using a regular expression on a user-input phone number - when I ask to print out the variable all I get is "+" instead of the whole phone numberprint "Enter the Comma Separated Text...:"; $str = <STDIN>; chomp($str); #Remove the quotes $str=~s/"//g; # @arr now contains the individual values @arr=split(",",$str); for($i=0;$i<=$#arr;$i++){ # if the array contains only digits if($arr[$i]=~/^d+$/){ $arr[$i]=$arr[$i]/2; } } print "Values in the Array are as Follows\n"; #print that Array foreach $val(@arr){ print "$val\n"; }
now I know you frown on homework help but if you could just tease me with a hint or two in the right direction...am I totally off track on these or am I in the neighborhood...? once again thanks for the wisdom monks sierra#Get the phone number and check to make sure that it contains only dig +its and the length is 10 while($phone =~ /D/ || $len !=10){ print "Please enter your 10 digit phone number:"; $phone = <STDIN>; chomp($phone); #Find out the length of the string $len=($phone=~tr/[0-9]/[0-9]/); } #Using regular expressions, break down the phone number into first num +ber the #next three digits and then the next three digits and so on. Each digi +ts will be #stored in $1 $2 $3 and $4. $phone=~/(d)(ddd)(ddd)(ddd)/; $formattedphone="+".$1." ".$2." ".$3." ".$4;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: wisdom needed for string matching and array processing
by friedo (Prior) on Nov 06, 2005 at 23:40 UTC | |
by sierrastar (Sexton) on Nov 07, 2005 at 00:24 UTC | |
by skx (Parson) on Nov 07, 2005 at 05:31 UTC | |
|
Re: wisdom needed for string matching and array processing
by Fletch (Bishop) on Nov 06, 2005 at 23:41 UTC | |
by sierrastar (Sexton) on Nov 07, 2005 at 00:06 UTC |