CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: basic search for elements: additional question: Edit Log



regex2012
User

Dec 14, 2015, 8:16 AM


Views: 4057
basic search for elements: additional question


Code
#!/usr/bin/perl 
use strict;

open my $fh9, '<', '/tmp/test2.txt' or die "unable to open file 'file' for writing: $!";
my @linesmon = <$fh9>;
close $fh9;


open my $fh8, '<', '/tmp/test1.txt' or die "unable to open file 'file' for writing: $!";
my @lines1 = <$fh8>;
close $fh8;

for my $policy (@lines1) {
my @newarray = grep {$policy} @linesmon;
print "@newarray\n";
}

I am trying to grep for the lines in test2.txt which contain the elements of test1.txt but it is not working. Not sure what I am doing wrong. I found that I get a printout of test2.txt but that the printout is the entire file, not a printout of the lines or data that contains the elements that are in test1.txt.


(This post was edited by regex2012 on Dec 15, 2015, 7:56 AM)


Edit Log:
Post edited by regex2012 (User) on Dec 14, 2015, 8:16 AM
Post edited by regex2012 (User) on Dec 14, 2015, 8:17 AM
Post edited by regex2012 (User) on Dec 15, 2015, 7:56 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives