> On Mon, 2005-03-07 at 15:59 +0100, Bruno Hertz wrote:
>
> > Without testing it, shouldn't it be
> >
> > $last = &longest_substring_in_common($_,$last);
> >
> > instead of
> >
> > $string = &longest_substring_in_common($_,$last);
> > ?
> >
> > Regards, Bruno.
No. That would only ever compare the first string (the one set to last)
to $_. I did test mine.
> OK, what about this
>
> #!/usr/bin/env perl
>
> use warnings;
> use strict;
>
> my $last=<>;
> chomp $last;
>
> while (<>) {
> last if not $last;
> chomp;
> $last = longest_substring_in_common($last,$_);
> }
> print "$last\n";
>
> sub longest_substring_in_common {
>
> my ($a,$b) = @_;
> foreach my $i ( 1 .. length($a)) {
> unless (substr($a,0,$i) eq substr($b,0,$i)) {
> return substr($a,0,($i-1));
> }
> }
> return $a;
> }
>
That should do it, but I didn't test.
--
xplanet -body earth -transpng a.png -geometry "300x300-0+0" -origin sun
My politics : http://satp.blogspot.com
Programmer
Attachment:
signature.asc
Description: Digital signature