sophisticatedpenguin
Technical User
Hi,
I'm VERY new to Perl. All I've learnt so far is some regular expressions, opening and closing files, and simple 'while' and 'if' loops. I wrote the following code to try to accomplish the following:
-open an input file
-for each line:
-find the text string before the tab character
-open a comparison file
-for each line:
-set a variable to "false"
-try to match the text string
-if it matches, set the variable to "true" and end the loop
-if the variable is still false at the end, write the text string to an output file
-then repeat for all the other lines of the input file
Here is the code (please try not to laugh too loudly):
The thing is that it worked fine when each file only had about 10 lines in it. But the real files are much bigger, and hours later the program is still churning ... Is there a more efficient way to do the same task?
Many thanks in advance for your patience with someone who is well out of her depth
SP
I'm VERY new to Perl. All I've learnt so far is some regular expressions, opening and closing files, and simple 'while' and 'if' loops. I wrote the following code to try to accomplish the following:
-open an input file
-for each line:
-find the text string before the tab character
-open a comparison file
-for each line:
-set a variable to "false"
-try to match the text string
-if it matches, set the variable to "true" and end the loop
-if the variable is still false at the end, write the text string to an output file
-then repeat for all the other lines of the input file
Here is the code (please try not to laugh too loudly):
Code:
#!C:\Perl\bin
use strict;
use diagnostics;
open(IFILE,"source.txt");
open(OFILE, ">compare_output.txt");
while (<IFILE>)
{
/\t/;
$phrase = $`;
$found = "false";
open (CFILE,"compare_with.xml");
while (<CFILE>)
{
if (/$phrase/i)
{
$found = "true";
last;
}
}
if ($found eq "false")
{
print OFILE "$phrase \n";
}
close (CFILE);
}
Many thanks in advance for your patience with someone who is well out of her depth
SP