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: [BillKSmith] Flagging list data hybrid situation: Edit Log



stuckinarut
User

Aug 23, 2015, 7:23 AM


Views: 2323
Re: [BillKSmith] Flagging list data hybrid situation


In Reply To
STEP 1:

Code
foreach my $key (sort {$map{$b}<=>$map{$a}} keys %map) {


Note: Although it is legal, it is poor practice to use perl key words as variable names because it can be confusing.

Sorry, I do not understand the requirement of STEP2.


Thanks, Bill. Maybe the Perl key words were 'throwing me for a loop' (PUN!) in trying to figure this part out :^) I would actually prefer to avoid poor practice, so will see how I can maybe revise things.

Regarding STEP 2, I'm not sure how better to explain the requirements but will try.

If I forget about trying to also integrate STEP 1 into STEP 2, maybe this will help.

Once the STEP 1 list is saved as 'listL.txt', everything is run as:


Code
perl step2.pl listD.txt listI.txt listL.txt >listscompared.txt


There are several 'Declaration' errors in the STEP 2 script to resolve, but I will try and explain better what needs to happen in this part:


Code
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";


In my original use of the script. if only the word 'peach' (WITHOUT ANY NUMBER) was in listL and in listD and listI, then the output would be:


Code
peach D I 
L: 1; D: 1; I: 1

NOTE:
L:1 indicates ONE list entry for 'peach'
D:1 indicates ONE match from list D
I:1 indicates ONE match from list I


But since list L actually now has 'peach 4' (a space and then number 4 after the word), then a REGEXP is needed to perform the matching on *only* the word - before the space and number.

Using the same above example if 'peach' is also on BOTH listD and listI, then the output (including the ACTUAL listL content) would be:


Code
peach 4 D I 
L: 1; D:1; I: 1


Using ONLY the 3 different list contents in the original post where peach is on listI but NOT on listD, here would be the final output:


Code
peach 4 I 
L: 1; D:0; I: 1


Perhaps this will make more sense?

Thanks again.

-Stuckinarut


(This post was edited by stuckinarut on Aug 23, 2015, 9:34 AM)


Edit Log:
Post edited by stuckinarut (User) on Aug 23, 2015, 7:26 AM
Post edited by stuckinarut (User) on Aug 23, 2015, 7:28 AM
Post edited by stuckinarut (User) on Aug 23, 2015, 7:32 AM
Post edited by stuckinarut (User) on Aug 23, 2015, 7:33 AM
Post edited by stuckinarut (User) on Aug 23, 2015, 8:00 AM
Post edited by stuckinarut (User) on Aug 23, 2015, 8:01 AM
Post edited by stuckinarut (User) on Aug 23, 2015, 8:02 AM
Post edited by stuckinarut (User) on Aug 23, 2015, 9:34 AM


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

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