#!/usr/bin/env perl # # previsprefix - print similar files # # $Id$ # on a sorted list of pathnames, prints the ones # that differ only in the directoryless pathname use warnings; use strict; my %printed = (); my %slashes = (); my %occurring_prefix = (); $| = 1; # flush output after every line my $prev = ''; $slashes{$prev} = 0; while (<>) { chomp; next if $_ eq $prev; while ( substr( $_, 0, length($prev) ) ne $prev ) { $prev = $occurring_prefix{$prev}; } $occurring_prefix{$_} = $prev; $slashes{$_} = y#/#/#; if ( $prev ne '' && $slashes{$_} eq $slashes{$prev} ) { # found a match - print it if ( !exists $printed{$prev} ) { print $prev . "\n"; $printed{$prev} = 1; } print $_ . "\n"; $printed{$_} = 1; } $prev = $_; }