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: [stuckinarut] Modify script to compare and flag lists: Edit Log



Laurent_R
Veteran / Moderator

Jun 12, 2014, 3:55 AM


Views: 40949
Re: [stuckinarut] Modify script to compare and flag lists

Just an additional point on your attempts.


Code
print ' H' if exists $H_list{$_} and $H_list{$_} == $L_list{$_};    
print ' A' if exists $A_list{$_} and $A_list{$_} == $L_list{$_};

is wrong because == is for numeric comparison, not alphabetical comparison, and also because this assumes the existence of a %L_list hash, which you have not created.


Code
print ' H' if exists $H_list{$_} and $_ eq $L_list;    
print ' A' if exists $A_list{$_} and $_ eq $L_list;

is never going to be executed because the condition will never be true, because $_ contains one line of your file and $L_list is a file handler (i.e. something like a pointer to your file) and they never going to be equal.

Similarly:


Code
print ' H' if exists $H_list{$_} and $H_list{$_} eq $L_list;    
print ' A' if exists $A_list{$_} and $A_list{S_} eq $L_list;

is also never going to be executed for the same reasons ($H_list{$_} is equal to 1)

You really need this:

Code
print ' H' if exists $H_list{$_}; 
print ' A' if exists $A_list{$_};

with no additional condition. If $_ is found in the hash, this is all you need to know. The value stored in the hash for the key $_ (1) is totally irrelevant.

BTW, if you used:

Code
use strict;  
use warnings;

as Bill and I have done in our examples of code and as you should always do, the Perl compiler would have told you about these mistakes.


(This post was edited by Laurent_R on Jun 12, 2014, 3:57 AM)


Edit Log:
Post edited by Laurent_R (Veteran) on Jun 12, 2014, 3:57 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