in reply to summarize similar strings
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11110672 use warnings; my $summary = <DATA>; while( <DATA> ) { /./ or next; my $xor = "$_" ^ "$summary"; substr $summary, $-[0], 1, '*' while $xor =~ /[^\0]/g; } print $summary; __DATA__ a/b/c/p0/m0/b0/r_a_c1_0/q a/b/c/p0/m0/b0/r_a_c1_1/q a/b/c/p0/m0/b0/r_a_c1_2/q a/b/c/p0/m0/b1/r_a_c1_0/q a/b/c/p0/m0/b1/r_a_c1_1/q a/b/c/p0/m0/b1/r_a_c1_2/q
Outputs:
a/b/c/p0/m0/b*/r_a_c1_*/q
Although you probably need some more extensive test cases :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: summarize similar strings
by abhay180 (Sexton) on Dec 28, 2019 at 07:11 UTC | |
by tybalt89 (Monsignor) on Dec 28, 2019 at 08:17 UTC | |
by abhay180 (Sexton) on Dec 28, 2019 at 08:59 UTC | |
by tybalt89 (Monsignor) on Dec 28, 2019 at 07:33 UTC |