
stuckinarut
User
Jun 12, 2014, 6:04 AM
Post #20 of 21
(35193 views)
|
Re: [Laurent_R] Modify script to compare and flag lists
[In reply to]
|
Can't Post
|
|
Laurent_R: I got back up out of bed on 3 hours of sleep to start combing through more Perl documentation on Hashes to see if I could find a solution. But first I checked this thread and WOW ... Thank You...I learned many things from your posting, and hope some of the other thread readers have too !!! Thank you for your persistence and tenacity to help me with with this matter (and the revised code). Your explanations were VERY educational. Part of the problem was, in fact, yes ... that the actual working lists (H, A, L) here were exported from WinDOZE Excel files. It never crossed my mind about trailing 'junk' spaces being part of the problem ;-( So I decided to be 'Bold' and added 2 more lists (F, N) to your code and cloned the Summary Total lines before running it. After the days & hours of frustrating "dead-ends", it was a thrilling relief to see this work (and then separately created a >zsummary.txt file) !!! I have named the script 'billandlaurent.pl' :^) :^) This will be used to compare other 'listL.txt' source files to H, A, F & N files which will be periodically updated, and also save a great deal of time in the future. Thank you so much again !!! - stuckinarut (But no longer in this matter) P.S. Actual list file counts used here: L = 2,845 H = 694 A = 735 F = 980 N = 710
use strict; use warnings; my %H_list; # ============================================================== # Special thanks to BillKSmith and Laurent_R at www.perlguru.com # for the code that works and tremendous educational experience! # ============================================================== open my $H_list, '<', 'listH.txt' or die "Cannot open listH.txt: $!"; while (my $line = <$H_list>) { chomp $line; $line =~ s/\r//g; # removes windows CR characters $line =~ s/\s+$//; # removes trailing white spaces $H_list{$line} = 1 } close $H_list; my %A_list; open my $A_list, '<', 'listA.txt' or die "Cannot open listA.txt: $!"; while (my $line = <$A_list>) { $line =~ s/\r//g; $line =~ s/\s+$//; chomp $line; $A_list{$line} = 1 } close $A_list; my %F_list; open my $F_list, '<', 'listF.txt' or die "Cannot open listF.txt: $!"; while (my $line = <$F_list>) { $line =~ s/\r//g; $line =~ s/\s+$//; chomp $line; $F_list{$line} = 1 } close $F_list; my %N_list; open my $N_list, '<', 'listN.txt' or die "Cannot open listN.txt: $!"; while (my $line = <$N_list>) { $line =~ s/\r//g; $line =~ s/\s+$//; chomp $line; $N_list{$line} = 1 } close $N_list; my ($L_count, $A_count, $H_count, $F_count, $N_count); open my $L_list, '<', 'listL.txt' or die "Cannot open listL.txt: $!"; while (<$L_list>) { chomp; s/\r//; s/\s+$//; $L_count ++; print; $H_count ++ and print ' H' if exists $H_list{$_}; $A_count ++ and print ' A' if exists $A_list{$_}; $F_count ++ and print ' F' if exists $F_list{$_}; $N_count ++ and print ' N' if exists $N_list{$_}; print "\n"; } print "L: $L_count; H: $H_count; A: $A_count; F: $F_count; N: $N_count \n";
|