Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by vinoth.ree (Monsignor)
on May 07, 2015 at 10:18 UTC ( [id://1125988]=note: print w/replies, xml ) Need Help??


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

Sorry, Wrongly understood the question.

Another approach is read the file2 content and split each line based on ':', and save in a hash, key will be 'enable_pad','c_pad','b_pad',etc and other string as value.

Read file1 and check each line exists in hash or not, if exists print it.

use strict; use warnings; open my $FILE2, "<", "file2.txt" or die "Cannot open file2 file: $!"; open my $FILE1, "<", "file1.txt" or die "Cannot open file1 file: $!"; my %hash; while (my $eachline = <$FILE2>) { chomp($eachline); my($key,$value)=split(':',$eachline,2); $hash{$key}=$value; } while (my $line = <$FILE>) { chomp($line) if(exists $hash{$line}) { print $line:$hash{$line} } else{print "$line does not exist in file2"} }

All is well. I learn by answering your questions...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2024-04-18 06:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found