Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How to read the regular expression from another file?

by pme (Monsignor)
on May 07, 2015 at 09:37 UTC ( #1125979=note: print w/replies, xml ) Need Help??


in reply to How to read the regular expression from another file?

Hi sumathigokul,
my @pattern = <STDIN>; # slurp patterns chomp @pattern; # remove end-of-line my $pattern = join '|', @pattern; # create regexp open F2, "<file2" or die "Cannot open file: $!\n": while (<F2>) { # read DATA print if /$pattern/; } close F2;
You can run this little script like this:
$ ./myscript.pl <file1

Replies are listed 'Best First'.
Re^2: How to read the regular expression from another file?
by MidLifeXis (Monsignor) on May 07, 2015 at 12:25 UTC

    In the spirit of TIMTOWDI, lines 6-8 could also be replaced by:

    print grep { /$pattern/ } <F2>;

    --MidLifeXis

Re^2: How to read the regular expression from another file?
by sumathigokul (Acolyte) on May 07, 2015 at 10:13 UTC

    Hi pme,

    Thank you so much, its working now....

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2023-06-07 08:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (29 votes). Check out past polls.

    Notices?