ThomasAllenDE has asked for the wisdom of the Perl Monks concerning the following question:

Greetings - I am not a Perl expert and am seeking Perl advice.

I am writing a script which looks through a directory and finds entries which are similar.

In the directory there may be entries for Oracle11*, Oracle10*, Office2003, Office2001, Offer, Groovy.

The question is, how do a take the string "Office2003", regard each letter separately, and then match letter for letter until a particular number of matching letters is reached, so I can say then names are similar?

For example, if the first 3 letters match, then Offer matches Office. But if I say "match" only when the first 6 letters match, then Office2001 matches Office2003, but not Offer

You help is very appreciated!

Thanks! - Tom

Replies are listed 'Best First'.
Re: Identifying Files with Similar Names
by Ratazong (Monsignor) on Mar 07, 2012 at 11:47 UTC
Re: Identifying Files with Similar Names
by JavaFan (Canon) on Mar 07, 2012 at 11:34 UTC
    use 5.010; ($x, $y) = ("office2003", "offer"); say length((($x^$y) =~ /(\x00+)/)[0]); __END__ 3
Re: Identifying Files with Similar Names
by nemesdani (Friar) on Mar 07, 2012 at 11:06 UTC
    F.e. you look for 6 letters, you can match a filename against
     /(^\w{6})(.*)/
    than store $1 and match other filenames with it.
    Now that I look at this, not an elegant solution, but it was the first thing that popped into my mind.