Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Filtering files with lists of substitution patterns

by golux (Pilgrim)
on Aug 29, 2013 at 13:21 UTC ( #1051433=note: print w/ replies, xml ) Need Help??


in reply to Filtering files with lists of substitution patterns

Hi LinuxMatt,

I'd suggest using qr to stringify each regex:

my @all_patterns = ( qr/#.*/, qr/^\s+/, qr/\s+$/, qr/^Total/, qr/^,/, # ... and so on ... );

Which avoids the overhead of calling an extra subroutine for each line of every file.

Then the apply_patterns subroutine would something like this:

sub apply_patterns { my ($string, @indexes) = @_; # Note $string is only a placeholder foreach my $idx (@indexes) { my $regex = $all_patterns[$idx]; s/$regex//; } }

Update:   Modified apply_patterns to work with $_[0] directly.

say  substr+lc crypt(qw $i3 SI$),4,5


Comment on Re: Filtering files with lists of substitution patterns
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1051433]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2015-07-29 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls