in reply to iterating over array to create smaller arrays based on pattern match
Iterate over the array and extract the prefixes. Use the prefixes as hash keys and push the filenames onto a hash-of-lists:
my @array = qw(001.file.a 001.file.b 002.file.a 002.file.b) ; my %groups; for my $filename ( @array ) { my $prefix = (split /\./, $filename)[0]; push @{ $groups{$prefix} }, $filename; } for ( keys %groups ) { print "group $_ has files @{ $groups{$_} }\n" }
Output:
group 002 has files 002.file.a 002.file.b group 001 has files 001.file.a 001.file.b
|
|---|