# read in file, make circuit ... use Data::Dumper; # 012345678901 <--(i)--> # 0 B+.....1.... # | 1 - . # (j) 2 . . # | 3 . . # 4 .........2.. # ======================= # C1:5 (for 5 uF) # C2:6 open (CIRC, "circ.txt"); $i = 0; $j = 0; while () { # put elements of circuit into m-d array last if $_ =~ /=+/; chomp; $i = 0; for $char (split //, $_) { push @{$Circ->[$i++][$j]}, $char } $j++; } $i = 1; $j = 0; while (1) { # count caps, make sure > 1 $on_i = $i; $on_j = $j; # make conditions for going up, dwn, lft, rt... if ($j-1 > 0) { LookAt ($i,$j-1) } # look up if ($j+1 < scalar @{$Circ->[$i]}-1) { LookAt ($i,$j+1) } # look down if ($i-1 > 0) { LookAt ($i-1,$j) } # look left if ($i+1 < scalar @$Circ-1) { LookAt ($i+1,$j) } # look up } sub LookAt { $l_i = $_[0]; $l_j = $_[1]; if (@{$Circ->[$l_i][$l_j]} eq '.') { print "i'm here" } }