$ perl -Mwarnings -Mstrict -E '
my @test_data = (
"comment follows: #qwerty",
" whitespace at start",
"whitespace at end ",
"Total: some total",
", starts with a comma",
);
my @all_patterns = (q{#.*}, q{^\s+}, q{\s+$}, q{^Total}, q{^,});
my @files = qw{file1 file2 file3};
my %file_filters = (
file1 => [0, 2, 4],
file2 => [2, 1, 3],
file3 => [4, 3, 2]
);
for my $file (@files) {
say "File: $file Patterns: @all_patterns[@{$file_filters{$file}}]";
my @this_files_data = @test_data;
for my $line (@this_files_data) {
say "Start: |$line|";
for (@{$file_filters{$file}}) {
$line =~ s/$all_patterns[$_]//;
}
say "End: |$line|";
}
}
'
File: file1 Patterns: #.* \s+$ ^,
Start: |comment follows: #qwerty|
End: |comment follows:|
Start: | whitespace at start|
End: | whitespace at start|
Start: |whitespace at end |
End: |whitespace at end|
Start: |Total: some total|
End: |Total: some total|
Start: |, starts with a comma|
End: | starts with a comma|
File: file2 Patterns: \s+$ ^\s+ ^Total
Start: |comment follows: #qwerty|
End: |comment follows: #qwerty|
Start: | whitespace at start|
End: |whitespace at start|
Start: |whitespace at end |
End: |whitespace at end|
Start: |Total: some total|
End: |: some total|
Start: |, starts with a comma|
End: |, starts with a comma|
File: file3 Patterns: ^, ^Total \s+$
Start: |comment follows: #qwerty|
End: |comment follows: #qwerty|
Start: | whitespace at start|
End: | whitespace at start|
Start: |whitespace at end |
End: |whitespace at end|
Start: |Total: some total|
End: |: some total|
Start: |, starts with a comma|
End: | starts with a comma|
####
File: file1 Patterns: #.* \s+$ ^,
Start: |comment follows: #qwerty|
End: |comment follows:|
####
File: file1 Patterns: \s+$ #.* ^,
Start: |comment follows: #qwerty|
End: |comment follows: |