in reply to Location of Conditional test effects results

You are falling prey to auto-vivification. After the lines
$editor = "no editor" if $record->{'services'}[0]{'class'} eq 'Pri +mary'; $editor = "no editor" if $record->{'services'}[0]{'class'} eq 'Sec +ondary';

the array element @{$record->{'services'}} contains one element - an anonymous hash holding at least the key class whose value might be undef.

You are looking at the value of $record->{'services'}[0]{'class'}, but to do that the key class in the hash %{$record->{'services'}[0]} has to exist, so perl just allocates the hash and the key for you. After that, the anonymous array has at least one element.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: Location of Conditional test effects results
by chakram88 (Pilgrim) on Apr 10, 2007 at 20:23 UTC

      Yes, I know that the eq test is putting up 'undefined' warnings on those $records where the secondary array is not defined. I deal with it in my full code,

      Had you fixed them, you would have fixed your problem too. Do not lightly ignore warnings in Perl.

        The problem I had was not understanding why the results changed when I moved the order of tests.

        I learned something from the other responses.

        I can modify the presented code to read

        $editor = "no editor" if $record->{'services'}[0]{'class'} && $rec +ord->{'services'}[0]{'class'} eq 'Primary';

        The warnings go away, but the odd results still are present. I don't lightly ignore warnings in Perl; in this instance I knew that the warning were not pointing to the problem.

        As I said, the warnings are not present in my full code, but I was narrowing down the code to smallest snippet possible to reproduce the error.

        Interestingly, I often am able to solve many questions I have by doing just such an exercise. Many times I've thought to seek the wisdom of the monks, only to figure out the answer while minimizing my code. I'm sure I'm not the only one.