Re: Finding the common textual denominator
On Mon, 2005-03-07 at 09:43 -0500, Josh Narins wrote:
> #!/usr/bin/env perl
>
> use warnings;
> use strict;
>
> my $string = '';
> my $last = '';
>
> while (<>) {
> if ($last) {
> $string = &longest_substring_in_common($_,$last);
> } else {
> $last = $_;
> }
> }
>
> print "$string\n";
>
> sub longest_substring_in_common {
> my ($a,$b) = @_;
> foreach my $i ( 0 .. length($a) ) {
> unless (substr($a,0,$i) eq substr($b,0,$i)) {
> return substr($a,0,($i-1));
> }
> }
> }
>
Without testing it, shouldn't it be
$last = &longest_substring_in_common($_,$last);
instead of
$string = &longest_substring_in_common($_,$last);
?
Regards, Bruno.
Reply to: