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

Perl reduces RSI - it saves typing

In reply to Re: ideas needed for finding matching characters in 2d array by GrandFather
in thread ideas needed for finding matching characters in 2d array by Anonymous Monk

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.