Did you write some code? We'd be glad to critique it and give pointers.

Thinking fuzzily before sufficient coffee, you want something like longest common substring.

Another way to look at it is to join the names, and match that way. Here's an untried, unsophisticated approach:

... # get the list of filenames (somehow) my @files = readdir; # make a copy my @files_copy = @files; # the number of files, less 1 my $file_count_less_one = $#files; # hash map for results my %new_file_names; # loop until explicit last while (1) { # join them with a character that's unlikely to be in the names my $joined = join('|',@files_copy); # look for matches, catch the first one only (they're all the same +) if (my ($match) = $joined =~ m/[^|]*?([^|]+)[^|]*?(?:[|][^|]*?\1[^ +|]*?){$file_count_less_one/) { # remove the matched substrings my @files_new; for my $file (@files_copy) { $file =~ s/$match//; push @files_new, $file; } # get ready for next loop @files_copy = @files_new; next; } else { # no more matches, make a hash map for the rename @new_file_names{@files} = @files_copy; last; # no more matches } } while (my ($old,$new) = each %new_file_names) { unless (rename $old, $new) { warn "Error renaming $old to $new"; } }

Lots of room for improvement there, including checking whether a new file name already exists, aliasing array elements in for loops, considering dir names in file names, etc.

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Re: how to guess mutual frases? by QM
in thread how to guess mutual frases? by Hossein

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.