in reply to File Intersection problem
To get you started, have a look at open, readline and close for your file handling. The three-argument form of open using lexical filehandles and testing for success (mention $!, O/S error, on failure) is recommended practice. E.g.
my $inputFile = q{xyz.txt}; open my $inputFH, q{<}, $inputFile or die qq{open: < $inputFile: $!\n}; my $outputFile = q{abc.txt}; open my $outputFH, q{>}, $outputFile or die qq{open: > $outputFile: $!\n};
Read your files in a while loop line by line, either into the default pattern space, $_ (see perlvar) or a lexical scalar. Consider whether to remove line terminators using chomp. E.g.
# Reading lines into $_ in a while loop and removing # line terminator while( <$inputFH> ) { chomp; # Acts on $_ by default ... # Rest of your line-processing code here }
Extracting the data fields could be done using regular expressions, have a look at perlretut and perlre. Consider using global matching in File 2 to extract a series of name data into an array. This pattern (not tested) looks like it will match data for one name, the whole data including the name captured in $1, the name alone in $2
my $rxExtractNameData = qr {(?x) ( \s+ (\w+) \s+ \([A-Z]\) \s+ \(\d*%\) \s+ \d+\s+\+\s+[+-]?\d+ ) };
Have a crack at putting some of these ideas together. Build your script gradually, first just getting it to open and close File 1 and, when that works, read the lines and extract the names (and numbers if necessary, do the numbers in File 1 have to match those in File 2?). If you encounter difficulties come back to the Monastery with more questions.
I hope these thoughts are helpful
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: File Intersection problem
by ashnator (Sexton) on Nov 13, 2008 at 08:26 UTC | |
by johngg (Canon) on Nov 13, 2008 at 22:41 UTC | |
by brsaravan (Scribe) on Nov 13, 2008 at 11:01 UTC |