Perl Hashes Question

Hi All,

I have a project where I need to find out if the Key or Value part of a Hash exists.

Here is a quick outline of the program:

I load a file and split each line into an array, using 3 values from the array (Say $Array[1], $Array[2], $Array[3]), i make up a Hash like so:

$Hash{$Array[1]."_".$Array[2]."_".$Array[3]}="Value";

This is all working fine and how I expected it to. The problem is that before I create the $Hash key, I want to check if it already exists. The reason for this is because it is possible for the 3 $Array[] values to be the same as a different line in the file. (Hope that makes sense.)

Ok, so, i have tried a few things, like if( $Hash{$Array[1]."_".$Array[2]."_".$Array[3]} ) { print "Something Already there" }

I understand that this looks to see if "Value" exists, not the actual key.

Can someone tell me a way that I can check if the "Key" part of the Hash has already been defined?

Any help would be much appreciated.

Thanks

-Hurgh-

Comments

  • Hi,

    : Ok, so, i have tried a few things, like if( $Hash{$Array[1]."_".$Array[2]."_".$Array[3]} ) { print "Something Already there" }
    :
    : I understand that this looks to see if "Value" exists, not the actual
    : key.
    :
    : Can someone tell me a way that I can check if the "Key" part of the
    : Hash has already been defined?

    [code]if (exists $Hash{$Array[1]."_".$Array[2]."_".$Array[3]}) {
    print "Something Already there";
    }[/code]

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion