in reply to Re: Is this logic valid?
in thread Is this logic valid?

Actually, I am comparing the string to a value from a key in a hash so here is some more code:
foreach $key (%hash) { if ($key{Value} le $variable) && (($key{Value1} eq 'String') && ($key{ +value2} eq 'String1')) { Do this.... }
Does this look any better?

Replies are listed 'Best First'.
Re: Re: Re: Is this logic valid?
by mpolo (Chaplain) on May 15, 2001 at 21:45 UTC
    Your code iterates over the keys and values of the hash one at a time, putting the result into $key, a scalar variable. Then it looks in a hash named %key... I think that what you really want is:
    foreach $currentkey (keys %hash) { }
    (If you're cool with $_, you can leave out $currentkey in that incantation.) I can't figure out exactly what you want in the comparison, though. $hash{$currentkey} will give you the value associated with the key currently in consideration. To get the hash value for another value, you can use $hash{'key_name'} if you are referring directly to a string value for the key, or $hash{$value1} if the variable $value1 contains the name of that key.
      Actually each key contains multiple values, so I think what I want is:
      foreach $currentkey (keys %hash) { if ($hash{$currentkey}{ValueNeeded} le $variable) { DO this.... }
      Does that clarify it any?
Re: Re: Re: Is this logic valid?
by no_slogan (Deacon) on May 15, 2001 at 21:43 UTC
    Mind your parentheses. Make sure your date format compares properly with a string compare ("2001-05-15" will, but "15 May 2001" and "2001-5-15" won't). What exactly is the problem you're having with this code?