Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: how to automate the regular expression match from a file?

by eff_i_g (Curate)
on Apr 06, 2011 at 19:37 UTC ( [id://897867]=note: print w/replies, xml ) Need Help??


in reply to how to automate the regular expression match from a file?

I recommend Regexp::Assemble for something like this. An example:
use warnings; use strict; use Regexp::Assemble; my @keywords = qw( a an the then that this ); my $key_rea = Regexp::Assemble->new; $key_rea->add($_) for @keywords; my $key_re = $key_rea->re; my $data = do { undef $/; <DATA> }; print "$1\n" while $data =~ m/(\b$key_re\b)/g; __DATA__ hello everyone, i had been trying to make a lexical analyzer for c, wh +ere all the keywords were to be inputted in a text file keywords. thi +s i stored in an array. but this process is not being automated. the +code i wrote is as follows :- ... the keywords file contains:- auto continue enum if short break switch +volatile default extern int signed typedef while case do float long s +izeof union char double for register static unsigned const else goto +return struct void

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2025-11-13 18:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (69 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.