[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] longest substring with unique characters



#!/usr/bin/perl -w

use strict;

while (<>) {
   chomp;
   my $longest = "";
   while (/./g) {
     my $match = $&;
     my $substr = $';
     ($match, $substr) = ($match . $&, $') while $substr =~ /^[^$match]/;
     $longest = $match if length($match) > length($longest);
   }
   print "$longest\n";
}

__END__

I guess this version is more perlish.
-- 
Julien

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe