Hi monks, I am back with another homework assignment - BUT I have done it all but somehow cant figure out why an array is not processing correctly - I need to get user input as comma delimited text or digits (i.e. dogs, cats, 4, 8) and then iterate the array and divide the digts if any by 2 and then print the whole thing out...I have gone over this a ton of times and can't figure out why it wont divide the digits (if any) by 2...here is the piece of code I wrote
print "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"; }
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 number
#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;
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

In reply to wisdom needed for string matching and array processing by sierrastar

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.