Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: identifying arbitury patterns in multiple strings

by si_lence (Deacon)
on Aug 18, 2005 at 19:07 UTC ( #484935=note: print w/replies, xml ) Need Help??


in reply to identifying arbitury patterns in multiple strings

Maybe not the most elegant solution (and I bet rather slow as well)
It finds the longest string that is at the start of every line in the
imput.
use warnings; use strict; my %ch; my $part; my $lines; while (<DATA>) { chomp; $part=""; map { $part .= $_; print $part."\n"; $ch{$part}++; } split (//); $lines ++; } my $max; foreach (keys (%ch) ) { if ( ($ch{$_} == $lines) and (length($_) > length($max)) ) { $max = $_; } } print $max; __DATA__ abcdefg abcd abcd grtf abcd abd abcd daf


si_lence

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://484935]
help
Chatterbox?
[Corion]: When you pass an arrayref, you get to treat it like a local array. But then, I'm cautious with the experimental features, because just when I thought function signatures were a set thing, there is a proposal to use sub [ $foo, $bar ] { ... } to ...
[Corion]: ... declare the parameters, instead of the more common sub ($foo, $bar) { ... }

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2017-11-17 20:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (272 votes). Check out past polls.

    Notices?