CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [FishMonger] Flagging list data hybrid situation: Edit Log



stuckinarut
User

Aug 23, 2015, 2:38 PM


Views: 2265
Re: [FishMonger] Flagging list data hybrid situation

Hello, FishMonger:

Thank you for your reply.

I will try to explain this better, and sorry for any confusion ;-(

This time, I will start with STEP 2 (a re-purposed and re-tweaked script from another task).

I finally got rid of the Declaration Errors, however discovered a new Mystery. So the STEP 2 script (to be further modified) *almost* works accurately using the these 3 lists:


Code
listD.txt 
grape
pear


And...


Code
listI.txt 
apple
grape
peach
pear


And...


Code
listL.txt 
apple
grape
grape
peach
peach
peach
peach
pear
pear
pear


When used in the following script:


Code
use strict;   
use warnings;

my %D_list;
my %I_list;
my %L_list;

open my $D_list, '<', 'listD.txt' or die "Cannot open listD.txt: $!";
while (my $line = <$D_list>) {
chomp $line;
$line =~ s/\r//g; # removes windows CR characters
$line =~ s/\s+$//; # removes trailing white spaces
$D_list{$line} = 1;
}
close $D_list;

open my $I_list, '<', 'listI.txt' or die "Cannot open listI.txt: $!";
while (my $line = <$I_list>) {
chomp $line;
$line =~ s/\r//g;
$line =~ s/\s+$//;
$I_list{$line} = 1;
}
close $I_list;

my ($L_count, $D_count, $I_count);
open my $L_list, '<', 'listL.txt' or die "Cannot open listL.txt: $!";
while (<$L_list>) {
chomp;
s/\r//;
s/\s+$//;
$L_count ++;
print;
$D_count ++ and print ' D' if exists $D_list{$_};
$I_count ++ and print ' I' if exists $I_list{$_};
print "\n";
}

print "L: $L_count; D: $D_count; I: $I_count \n";


This is the output:


Code
apple 
grape I
grape D I
peach I
peach I
peach I
peach I
pear D I
pear D I
pear D I
L: 10; D: 5; I: 10


For some reason, the first 'grape' line 'D' flag is missing, and the second 'apple' line 'I' flag is missing but I cannot figure out why ;-(

The Total D and I counts at the bottom are correct based upon the actual D and I lists which are matched, but why the 2 entries are not flagged remains a Mystery.

Once this script framework is working 100%, then the OBJECTIVE is to 'integrate' the correct sorting code fixed with BillKSmith's solution and the CONSOLIDATED (SHORTENED) "L" list so that the output looks like this, with the D and I flags:


Code
peach 4 I 
pear 3 D I
grape 2 D I
apple 1


NOTE: Or to keep the STEP 1 script and processing separate, and then use that output for the lineL.txt input. That's where I'm lost because of the 2 data columns involve instead of just one.

I am using fruit names as examples rather than various strange looking data codes which would only make things more confusing.

Does this help?

I appreciate your efforts to help!

-Stuckinarut


(This post was edited by stuckinarut on Aug 23, 2015, 2:41 PM)


Edit Log:
Post edited by stuckinarut (User) on Aug 23, 2015, 2:40 PM
Post edited by stuckinarut (User) on Aug 23, 2015, 2:41 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives