in reply to Grouping files with the same name...
use File::Spec::Functions qw( catfile ); sub get_files_in_dir { my ($dir_name) = @_; opendir(my $dh, $dir_name) or die("Unable to open dir \"$dir_name\": $!\n"); return map catfile($dir_name, $_), grep -f, grep !/^\.\.?\z/, readdir($dh); } my $dir_name = '...'; # Get list of files. my @files = get_files_in_dir($dir_name); # Group files by customer. my %files_by_cust; foreach (@files) { my ($cust_id) = /^customer(\d+)\./ or next; push @{ $files_by_cust{$cust_id} }, $_; } # Process each customer's files. foreach my $cust_id (keys %files_by_cust) { # List of files is in @{ $files_by_cust{$cust_id} }. # ... }
Updated: Added omitted call to opendir.
|
|---|