in reply to Re^2: Hash ref assignment to array results in anomaly
in thread Hash ref assignment to array results in anomaly

The problem stems, as I already described, from your top-level declaration of $switch_optional. You're not initializing it there, so Perl initializes it to a hash reference when you first use it as a hash reference. As you never change the value of the reference, Perl keeps that value. You then push, in the loop, that reference onto your array. So Perl pushes that same value of the same reference to your array. Three times in total.

If you reduce your program to the relevant part, you actually find out what parts are irrelevant and what parts are relevant. This is an important capability to have or to evolve, if you want to have any chance at succeeding to program. So please, show the effort and reduce your program to only the relevant parts.