http://qs1969.pair.com?node_id=216313


in reply to For loop problem

for ($d=1;$d<10;$d++){
That's going to iterate $d from 1 to 9. Its valid syntax, but its easier to read, and more perlish this way:
for my $d ( 1..9 ) {

if ($line =~ /^(\d{1,10})/){
This is going to evaluate to true if $line contains a string of numbers. It will assign up to the first 10 consequitive numbers into $1.

if ($d =~ /^$key$/){
This is going to evaluate true if the string of numbers is contained within $d. In other words, this is going to evaluate to true if the very first string of numbers that you found in $line was a single digit between 0 and 9. So, any of the following lines are guaranteed to never match:

this is my 023 string
hello 10
hi there 0
how are you 03