in reply to ideas needed for finding matching characters in 2d array
Scan the data to find the coordinates for each character and save the results in a hash of arrays (one hash entry for each character encountered). Then run through the hash and generate the report:
use strict; use warnings; my @words = qw(book reboot rocket); my @chars = map {[split '']} @words; my %matches; for my $row (0 .. $#chars) { for my $column (0 .. $#{$chars[$row]}) { push @{$matches{$chars[$row][$column]}}, [$row, $column]; } } for my $char (sort keys %matches) { next unless @{$matches{$char}} > 1; print "$char=", join (',', @$_), "\n" for @{$matches{$char}}; }
Prints:
b=0,0 b=1,2 e=1,1 e=2,4 k=0,3 k=2,3 o=0,1 o=0,2 o=1,3 o=1,4 o=2,1 r=1,0 r=2,0 t=1,5 t=2,5
|
|---|