I am comparing the contents of two files, but the comparison is done inside of a foreach loop (the code that i have so far is below). At the instance the files are different, i want to capture one of the files and use it later on in the script. But it keeps iterating through the loop and is only capturing the last one in the array. Is there a way to do this? I tried to use the 'else' statement after the compare, so that if the compare is false, i could save the file i wanted in another variable and use it later, but for some reason it doesn't like that.
Here is example of what the loop does:
$copiedfile will compare to each of the $file that are saved in the @result_files array.
$copiedfile will compare to $file which is @result_files[0]
and also
$copiedfile will compare to $file which is @result_files[1]
Expand|Select|Wrap|Line Numbers
- $known_messages_dir = "C:\\Test Data\\Results\\";
- $copied_results_dir = "C:\\Test Data\\Copied_Results\\copied_results.txt";
- for ( my $i = 0; $i <= $#{$testcase{output_messages}}; $i++ )
- {
- foreach $file (@result_files)
- {
- my $file1 = $known_messages_dir.$testcase{output_messages}[$i];
- my $copiedfile = $copied_results_dir;
- $matches_delta = $matches;
- if (compare( "$copiedfile","$file" ) == 0)
- {
- print REPORT_FILE "\nPASS - Results matched for $testcase{output_messages}[$i]\n";
- matches++;
- last;
- }
- } #End of FOREACH loop
- if ($matches_delta == $matches )
- {
- .
- .
- Within this IF statement, execute the code using the $file at the instance that $copiedfile and $file are different (from the above ‘compare’ line)
- .
- .
- }
- } #End of FOR loop
Thanks,
Terra