http://www.perlmonks.org?node_id=1005345


in reply to Re: Replacing If Elsif Else with Hash
in thread Replacing If Elsif Else with Hash

To be honest, I am not exactly sure. The portion of code involves some simple Image::Magick and would run, but would not write the final output image from the external subroutine. I spent most of the day trying to figure out why the image wasn't being created.

I ended up slowly rebuilding the subroutine with small portions, and running with each small addition until the point when the image wasn't being written again, and it turned out to be the if elsif else portion. In the end, I had a subroutine with exactly the same code, with everything except that section.

I use strict and warnings, nothing ever showed up, so I can only assume there was some sort of collision with Image::Magick but not sure what. I even tried changing both $severity and $background to different string names, at first thinking maybe one of them was colliding with something, but still, no image would be written.

With both the hash version I did, and the one suggested by frozenwithjoy, they both work fine in the external sub.

I am still curious as to why it did not work that way, but in the end I am happy that I was at least able to track down what part of the code was causing the problem, and find a solution.

  • Comment on Re^2: Replacing If Elsif Else with Hash

Replies are listed 'Best First'.
Re^3: Replacing If Elsif Else with Hash
by roboticus (Chancellor) on Nov 24, 2012 at 14:05 UTC

    johnfl68:

    If everything worked find (i.e. no error messages, etc.) and if failed only because of the addition of the if/else block, then I think I'd suspect one or more of your braces was a line too high or too low, causing the code to be bypassed or some such. Pure speculation, though.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.