in reply to Removing duplicate filenames in different directories from an array
You could put the file-names to keep in an array. Perl will waste a bit of space on empty slots, but so long as the largest number is not huge it should be efficient.
my @filenames foreach my $file (@files) { if( $file =~ m:/file-(\d+)-2.txt$: ) { $filenames[$1] = $file; } else { warn "Unexpected file found: $file\n"; } } foreach my $file (@files) { print $file if defined $file; }
This method will silently discard duplicates, which may or may not be a problem for what you are trying to do, but it will be fast.
|
|---|