in reply to Re^2: Find common prefix from a list of strings
in thread Find common prefix from a list of strings
but I prefer the chop.#!/usr/bin/perl -wl use strict; use warnings; sub Prefix { my $p = shift; ($p)=$_=~join'','\A',map("(\Q$_",split//,$p),join'?',(')')x length( +$p)or return'' for @_; $p } while (<DATA>) { print "$_=> ", Prefix(split ' ',$_); } __DATA__ model4run1 model2run1 model4run2 model1run1 model4run1 model2run1 model4run2 abbot model4run1 model2run1 abbot model1run1 model4run1 model2run1 model4run2 monk model4run1 model2run1 monk model1run1 testing terse testing time
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Find common prefix from a list of strings
by slink (Initiate) on Feb 22, 2014 at 11:57 UTC | |
by choroba (Cardinal) on Feb 22, 2014 at 12:14 UTC | |
by ysth (Canon) on Feb 23, 2014 at 04:03 UTC |