Do you know where your variables are? | |
PerlMonks |
Re: Problem when comparing strings as opposed to numerical valuesby ig (Vicar) |
on Jul 19, 2012 at 20:50 UTC ( [id://982715]=note: print w/replies, xml ) | Need Help?? |
I wonder if you are missing quotes in your second if. I'm guessing that you also need to put quotes around your strings in what I'm guessing you want to be a string eval (the second if). The string you want to evaluate should probably be something like "'string' eq 'string'". It might help you to examine what you are evaluating. You might use the debugger but I would probably use print or warn myself. Something like:
When you see what you are evaluating, the problem will likely become evident. FWIW: I don't think I would use eval as you are trying to. I would probably do something more like the follwing:
If I was going to use eval, I would definitely check for errors after each eval. I suspect if you did so, you would find that the eval in your second if gives a compile error - but it's only a guess. If you did add error handling to your implementation with eval, I would find it even harder to read than what you have currently, which is already too hard for my taste, but that's just me. In any case, if you want to know why your program isn't doing what you expect, a very good place to start is error handling and reporting. To this end, you might find strict and warnings helpful.
In Section
Seekers of Perl Wisdom
|
|