in reply to help manipulating data in an array.
One last thing if you are looking for number ending in some sequence of digits, in this case '9432' you do not need to use the ^ anchor, just the $ anchor, since the ^ indicates to the regexp engine that you are checking from the beginning of the string. The $ indicates the end of the string, so your pattern would be /9432$/ since you are trying to match the end.#the foreach style sets a variable, in this case $num, to #each element of your array. If you did not specify a #variable, then the special variable $_ would be set #each time through. foreach my $num (@number){ if($num =~ /9432$/){ print "match found"; }else{ print "match failed"; } } #a C-style for loop in which case you will be using #the $i variable to count from 0 to the end of your array #based on how big it is which we now know is scalar @number. for(my $i=0 ; $i < scalar @number ; $i++){ if($number[$i] =~ /9432$/){ print "match found"; }else{ print "match failed"; } }
|
|---|