in reply to Re^2: comparing lists
in thread comparing lists

I see you are using if (defined $xxx{$yyy}) where you probably intended if (exists $xxx{$yyy})

In general it is useful to provide the fail reason for opens using $!:

open(NCLIST, $ncaccts) || die ("Cannot open $ncaccts: $!");

The line open($output, '>', 'output.txt' || die "Cannot open output file output.txt"); has a missing ) and (. It should be open($output, '>', 'output.txt') || die ("Cannot open output file output.txt: $!");

You should always use the three parameter open. It makes the input explicit and in other contexts where the file name is provided by the user avoids malicious effects from a user putting > at the start of a file name.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^4: comparing lists
by Anonymous Monk on Feb 04, 2006 at 22:44 UTC
    Thanks a lot! That cleared up many things. I had to make one other slight modification...in the while loop, I cannot use LAST, rather I want to use NEXT at the end also because I want to continue to check until the end of the file rather than break the loop as soon as the last requirement is met.

    while ($line = <ORIGACCTLIST>){ chomp $line; ($filename, $state, $amt, $ttl, $account, $name, $invnum) = split /\t/ +, $line; $name =~ s/\s+$//g; next if exists $exclusionlist{$account}; print $output "$filename\t$state\t$amt\t$ttl\t$account\t$name\t$invnum +\n"; if (exists $ncacctlist{$account}) { print $ncoutput "$filename\n"; next; } if (exists $ccacctlist{$account}) { print $ccoutput "$filename\n"; next; } if (exists $ccnamelist{$name}) { print $ccoutput "$filename\n"; next; } print $ncoutput "$filename\n"; next; }