LinuxMatt has asked for the wisdom of the Perl Monks concerning the following question:
I have to process many kinds of text files in order to filter out contents. For each kind of file there is a list of susbstitution patterns to be applied on each line.
I would like to store all possible patterns in an array. Then I would call a subroutine on each line with the list of patterns to apply.
Example of pseudo-code:@all_patterns = (s/#.*//, s/^\s+//, s/\s+$//, s/^Total//, s/^,// ); # and so on while(<FILE1>) { apply_patterns($_, (0,2,3)); # apply patterns 0, 2 and 3 } while(<FILE2>) { apply_patterns($_, (2,5,7)); # apply patterns 2, 5 and 7 } while(<FILE3>) { apply_patterns($_, (5,4,3)); # apply patterns 5, 4 and 3 }
How is it possible to write the 'apply_patterns' subroutine ?
Thanks for your help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Filtering files with lists of substitution patterns
by BrowserUk (Patriarch) on Aug 29, 2013 at 12:44 UTC | |
|
Re: Filtering files with lists of substitution patterns
by Athanasius (Archbishop) on Aug 29, 2013 at 13:25 UTC | |
|
Re: Filtering files with lists of substitution patterns
by kcott (Archbishop) on Aug 29, 2013 at 13:33 UTC | |
|
Re: Filtering files with lists of substitution patterns
by Eily (Monsignor) on Aug 29, 2013 at 13:27 UTC | |
|
Re: Filtering files with lists of substitution patterns
by golux (Chaplain) on Aug 29, 2013 at 13:21 UTC |