in reply to Re: Find the common beginning substring in an array of strings (Updated)
in thread Find the common beginning substring in an array of strings
But that doesn't work for arrays with odd numbers of elements:
>perl -wMstrict -MData::Dump -le "my @array_of_test_names = qw(ABCxyz ABCDEfoo ABCDbar); ;; my $mask = '';; $mask ^= $_ for @array_of_test_names;; dd $mask; ;; my $len; $mask =~ m[^(\0+)] and $len = length( $1 );; my $min = substr $array_of_test_names[ 0 ], 0, $len;; print qq{'$min'}; " "ABCx^}\35o" Use of uninitialized value $len in substr at -e line 1. ''
Update: I didn't see mbethke's post until after I posted, but I agree that simple fix will solve the odd-element problem.
|
|---|