in reply to Re: Line by line parsing from one file, comparing line by line to another file
in thread Line by line parsing from one file, comparing line by line to another file
#!/usr/bin/perl<br> use strict;<br> use warnings;<br> <br> # 777297<br> <br> my $data_file = "test1.txt";<br> open(DATA, $data_file) || die("Could not open file!");<br> my @data_file = <DATA>;<br> <br> my $names_file = "code.txt";<br> <br> open(NAMES, $names_file || die "Could not open file!");<br> my @names_data = <NAMES>;<br> <br> # create loop that reads each ID in code.txt (NAMES array), searches f +<br> #+or each in array elements for #test1.txt<br> # (DATA array), redirects a new (NAMES).html for each element<br> <br> my ($names, $data);<br> for $names(@names_data) {<br> chomp($names);<br> for $data(@data_file) {<br> chomp ($data);<br> if ($data =~ /$names/) {<br +> print "found \$names ( $names ) in \$data \n";<br> push @data, qq | > $names.html "\n";<br> }<br> }<br> }<br> <br> close NAMES;<br> close DATA;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Line by line parsing from one file, comparing line by line to another file
by ww (Archbishop) on Jul 05, 2009 at 11:25 UTC | |
by web_developer (Initiate) on Jul 05, 2009 at 22:08 UTC |