Nested while loop which does not seem to keep variables appropriately?

Your code is not entering the PATCHLIST while loop the 2nd time through the SYSTEMINFO while loop because you already read all the contents of PATCHLIST the first time through. You'd have to re-open the PATCHLIST filehandle to accomplish what you're trying to do That's a pretty inefficient way to see if the lines of one file match the lines of another file. Take a look at grep with the -f flag for another way grep -f PATCHFILE SYSTEMINFO.

Your code is not entering the PATCHLIST while loop the 2nd time through the SYSTEMINFO while loop because you already read all the contents of PATCHLIST the first time through. You'd have to re-open the PATCHLIST filehandle to accomplish what you're trying to do. That's a pretty inefficient way to see if the lines of one file match the lines of another file.

Take a look at grep with the -f flag for another way. Grep -f PATCHFILE SYSTEMINFO.

I believe this is closer to what I needed, but I am having trouble locating documentation for grep -f. I tried the following, but this isn't what I need either. I think I'll revist tomorrow: while() { $pline = $_; @matching_patches = grep {$pline} @system_info; } print @matching_patches; – Boyd Apr 11 at 0:42 Actually you could call seek $fh, 0, 0; – Brad Gilbert Apr 11 at 1:52.

The normal (and much more efficient! - it only requires you to read in each file once, rather than reading all of one file for each line in the other) way to do this in Perl would be to read the lines from one file into a hash, then use hash lookups on each line in the other file to check for matches. Untested (but so simple it should work) code: sub patch_check { my %slines; while () { # Since we'll just be comparing one file's lines # against the other file's lines, there's no real # reason to chomp() them $slines{$_}++; } # %slines now has all lines from SYSTEMINFO as its # keys and the values are the number of times the # line appears, in case that's interesting to you while () { print "match: $_" if exists $slines{$_}; } } Incidentally, if you're reading your data from SYSTEMINFO and PATCHLIST, then you're doing it the old-fashioned way.

When you get a chance, read up on lexical filehandles and the three-argument form of open if you're not already familiar with them.

1 for proving that I use a good method for solving such tasks and providing the same solution at the same time. – stema Apr 11 at 9:38.

What I like to do in such cases is: read one file and create keys for a hash from the values you are looking for. And then read the second file and look if the keys are already existing. In this way you have to read each file only once.

Here is example code, untested: sub patch_check { my %patches = (); open(my $PatchList, ' ) { $patches($PatchRow) = 0; } while ( my $SystemRow = ) { if exists $patches{$SystemRow} { #The Patch is in System Info #Do whateever you want } } }.

Of course, this version will report every line as a duplicate, since you're comparing patch. Txt against itself. :) – Dave Sherohman Apr 11 at 9:48 @Dave: Corrected, copy paste ... – stema Apr 11 at 9:58.

You can not read one file inside the read loop of another. Slurp one file in, then have one loop as a foreach line of the slurped file, the outer loop, the read loop.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions