blackbeard has asked for the wisdom of the Perl Monks concerning the following question:
But here dealing with FILE1 a text file containing a cfg pushed to a network element and FILE2 a text file copy of the cfg on the same device is causing me difficulty. Basically, check that all lines in FILE1 are resident in FILE2.
The white space that the router throws in caused the code to report that a line isnt resident when in actually it is, but maybe with an extra space somewhere in the line.So the question is, how do I turn off white space checking
I tried tobut that didnt work because the lines being compared were still different ... humm just had a thought ... how about running through the array and just removing all white space and dump into @clean, then do the same to $line just prior to the grep ... then just a single string of characters ... right ?foreach $item (@xray){ $item =~ s/^ *//g; $item =~ s/ *$//g; $item =~ s/\s+/ /g; push(@clean, $item); }
open (FILE1, "$file1_val") or die; open (FILE2, "$file2_val") or die; @xray=<FILE2>; for $line (<FILE1>) { if (!(grep $line eq $_, @xray)) { print "$line\n" } } close FILE1; close FILE2; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Match but ignore white space
by pc88mxer (Vicar) on May 09, 2008 at 15:08 UTC | |
|
Re: Match but ignore white space
by grizzley (Chaplain) on May 09, 2008 at 15:56 UTC | |
|
Re: Match but ignore white space
by jhourcle (Prior) on May 09, 2008 at 16:31 UTC | |
by pc88mxer (Vicar) on May 09, 2008 at 17:10 UTC |