Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Filter script with pattern and an array

by reneeb (Chaplain)
on Oct 03, 2005 at 11:37 UTC ( [id://496874]=note: print w/replies, xml ) Need Help??


in reply to Filter script with pattern and an array

You should use use strict and use warnings

I would suggest, that you make one regex, which includes all elements of @Filter... So you just have to test one time instead of many iterations...

#!/usr/bin/perl use strict; use warnings; my $infile = @ARGV[0]; my $outfile = "OK.txt"; my @Filter = ('01005;01000','01005;01001','01005;01002','01005;01003') +; my $zaehler = 0; open(INFILE, "< $infile") or die "\nDatei $infile konnte nicht geoeffn +et werden\n"; open(OUTFILE, "> $outfile") or die "\nDatei $outfile konnte nicht geoe +ffnet werden\n"; my $filterregex = join('|',@Filter); while (<INFILE>) { if(/$filterregex/){ print OUTFILE $_; $zaehler++; } } close(INFILE); close(OUTFILE);

Replies are listed 'Best First'.
Re^2: Filter script with pattern and an array
by reneeb (Chaplain) on Oct 03, 2005 at 11:47 UTC
Re^2: Filter script with pattern and an array
by ultibuzz (Monk) on Oct 03, 2005 at 12:13 UTC
    can regex handel 60000 elements ? so it will look like this while (<INFILE>) { print OUTFILE if /01005;01000|01005;01001|01005;01002|01005;01003|...untill 60ooo element|03584;66689/ }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-20 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found