in reply to Re: How do i do a direct comparison of an array of strings?
in thread How do i do a direct comparison of an array of strings?

Actually, you don't even have to bother with the  tr stuff if you only want the differing positions:
>perl -wMstrict -le "my ($x, $y) = qw{abXcdYef pqXrsYtu}; my @i_diffs = differing_positions($x, $y); print 'number of differences: ', scalar @i_diffs; print qq{differing positions: @i_diffs}; sub differing_positions { my $i = 0; map $_->[1], grep $_->[0] ne qq{\x00}, map [ $_, $i++ ], split '', $_[0] ^ $_[1] ; } " number of differences: 6 differing positions: 0 1 3 4 6 7

Replies are listed 'Best First'.
Re^3: How do i do a direct comparison of an array of strings?
by gone2015 (Deacon) on Feb 20, 2009 at 01:13 UTC

    Or even:

    sub differing_positions { my @c = unpack('C*', $_[0] ^ $_[1]) ; return grep $c[$_], (0..$#c) ; }