in reply to processing key value pairs of a hash

Hi,

First of all: You write good code.

Now on to the critisism (I don't quite understand what you are trying to achive (your file at the top has 2 fields but in your script you seem to deal with 10 of them and I had too much beer to guess what you probably could mean - which is why I will focus purely on formal stuff :-)

1) "perl -w" in the she-bang line and "use warnings" are pretty much the same thing (won't hurt of course :-)

2) You should check the result of your open-statements e.g. "open my $fh, "file" or die $!;"

3) Don't repeat yourself. Put the (common) directory that your files share into a variable, then you only have to change one line of code should you ever want to access files in a different directory.

4) Why chomp the first line when you want to discard it anyway?

5)The keys of your %clone_hash seem to be strings so you should simply sort them using cmp.

  • Comment on Re: processing key value pairs of a hash

Replies are listed 'Best First'.
Re^2: processing key value pairs of a hash
by toolic (Bishop) on Apr 14, 2009 at 20:52 UTC
    1) "perl -w" in the she-bang line and "use warnings" are pretty much the same thing (won't hurt of course :-)
    Here is the difference, according to warnings:
    The warnings pragma is a replacement for the command line flag -w , but the pragma is limited to the enclosing block, while the flag is global. See perllexwarn for more information.
      Don't get your posting...

      I know there is difference that's why I said "pretty much the same" and not "exactly".

      For his case (as he does not seem to want to turn warnings off for a particular lexial scope) it won't make a difference.

      But ok:

      6) Don't use -w, always use warnings so you can turn them off again.

        The reason for my posting was to provide additional, specific information -- in the form of a link to the official Perl documentation -- as to the differences between -w and warnings, mostly for the benefit of the OP (or anyone else who is interested). It is good that you brought this to the attention of the OP.
        Thanks morgon!
      Thanks Toolic!
Re^2: processing key value pairs of a hash
by lomSpace (Scribe) on Apr 15, 2009 at 13:04 UTC
    Hi Morgon!
    Thanks for the response and the cudo's on my code! Yes, the keys are strings and I understand that keys are unique. I want to process each unique string based on all of the values
    For example, the string 'Eif2b2' I want to count only the value 'pass2'. Remember
    that for each string I am only interested in counting values from 'pass1' to 'pass3'
    and then counting only those key value pairs where after I remove 'pass4' and
    greater there is only one key value pair that is less than 'pass4'.
    Thanks,
    LomSpace