Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Is this logic valid?

by mincus (Chaplain)
on May 15, 2001 at 20:40 UTC ( [id://80607]=note: print w/replies, xml ) Need Help??


in reply to Is this logic valid?

Unless I am missing something... it looks as if you are compairing quoted strings and not variables.

('ShowPersonal' eq 'Personal')

will never evaluate to true. without seeing more of your code I can only guess that you either mean

($showpersonal eq 'Personal') and hopefully not ('$showpersonal' eq '$personal') there is a very big difference between what you have and the two examples that I have shown. Mine use variables, which, hopefully would be modified in your program, so that they would contain the values of something useful to compare, and in the second example that I give, you are compairing the quoted string $showpersonal and $personal, not the two variables $showpersonal and $personal.

here are some good documents that you may want to look over, and you might also consider posting more of the code that you are working with.

check this out and perhaps this as well. good luck!

Replies are listed 'Best First'.
Re: Re: Is this logic valid?
by wstarrs (Acolyte) on May 15, 2001 at 21:27 UTC
    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?
      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?
      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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://80607]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found