in reply to Re: grep in if statement not working as expected
in thread grep in if statement not working as expected

I can't, because if I fix the problem you mention, then the problem I describe in this post both disappears in the chopped version of my code posted here, and in the real, full version.

Below is a patched exception.t that completely fixes my problem, because by fixing the bug you mentioned, it also fixed the bug I though I was having. Unfortunately, it was foolish enough, and I was too frustrated to spot it before posting here for help. JavaFan thanks for pointing out my stupid mistake, because I really did think I was having the problem I previously described.

#!perl # exception.t tests all of Exception. use strict; use warnings; use diagnostics; use 5.010; use Test::More;# tests => '19'; BEGIN { use_ok('Exception', 'create_exception'); } # Test uneven params. # create exception w/params create_exception('ParameterException', 'description', 'param', 'param2 +'); evalok(sub {eval {die Exception->throw('ParameterException', param =>) +};}, <<EOD, 'check throw()ing uneven params'); You tried to throw an exception that had an uneven number of parameter +s and their values. The list of parameters you provide must be an even numb +er of parameters followed by their values as in a hash. (ex: 'exception' a = +> '1', b => '2', c => '3') EOD done_testing(); # runs code, and validates the $@ error message. # Why make people install Test::Exception if this little bit of code i +s all # that's needed? sub evalok { my ($code, $expected_message, $test_name) = @_; $code->(); my $croak = $@; $croak =~ s/\sat.*\n$//; #remove cruft. is($croak, $expected_message, $test_name); }

The fix was simply creating the exception with create_exception() before trying to throw it. In the previously posted code, I though I was, but it was creating an exception named ParameterException, but using an exception named TestException.

JavaFan, I feel kinda foolish for posting code that doesn't even have the problem I think it does. Anyway, thanks for the extra set of eyes that made this nightmare I wasted hours debugging seem trivial and foolish. I guess this is what I get for creating new tests by copy and pasting code from previous tests, and forgetting to change all of the variables for the new code.