Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: matching an array of alternates

by btrott (Parson)
on Jun 23, 2000 at 23:17 UTC ( #19645=note: print w/ replies, xml ) Need Help??


in reply to matching an array of alternates

Build a regular expression that will match those countries, then scan through the file and check each line against it:

my $regex = join '|', @latin_am; while (<>) { print $1 if /$regex/; }
This reads from STDIN, so invoke it like this:
% foo.pl file


Comment on Re: matching an array of alternates
Select or Download Code
RE: Re: matching an array of alternates
by Zoogie (Curate) on Jun 23, 2000 at 23:54 UTC
    Just wanted to point out that if the file you're searching has a lot of lines, you can gain some speed by adding the "o" option to the regex; i.e.:
    print $1 if /$regex/o;
    This way, the regular expression only has to be compiled once.

    - Zoogie

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-09-22 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (202 votes), past polls