Question about comparing one file to another in Perl
I have a perl project that take a csv file and then process it. It will take the records and put them in different files depending on the results of the processing, such as, if the record is to many pages it will place the record in a bad record file and if the record is printed by an exempted staff member it will place the record in the staff file. There is a separate file that holds the exempted staff members
The problem I have is when I try to compare the record to the exempted staff file. Here is how I do it so far: Code:
open(IN, "etc/except.txt"); Code:
while(<IN>) { obviously there are other statements that process the rest of the records, but they work just fine. For some reason this ends up placing all record into the staff file. How do I get this fixed? |
instead of = try eq or == if its a numeric record, = is for assignment and evaluates true
|
that worked, however is there anything I need to do other than that?
Like for ($i=0; $i<$count+1; $i++) { or something? It should not be cutting off the last name in the exempt file should it? |
$count = @except for the number of elements in the array should work just fine and your original loop should iterate through all the elements in except. You also probably want chomp instead of chop. You could make this more efficient by using a hash instead.
In your @except loading loop replace push(@except, $_); with $except{$_} = 1; and then eliminate that whole inner loop Code:
$count = @except; Code:
if ($except{$a[5]} == 1) { |
First and foremost, use
use strict; use warnings; in the beginning of you program/module - they show you a lot of problems. |
All times are GMT -5. The time now is 05:26 PM. |