in reply to Re^7: Adding hashes to already existing array
in thread Adding hashes to already existing array

I have been bitten by that enough times. In this case, since the array was created by using /($re2)/, would it be necessary to test against $re2 in this case?

  • Comment on Re^8: Adding hashes to already existing array

Replies are listed 'Best First'.
Re^9: Adding hashes to already existing array
by stevieb (Canon) on May 06, 2016 at 23:12 UTC

    Always. Always check to ensure you have a match before you assign/use a numbered special var. If you're doing $something = $1, ensure $1 has what you want first.

    Test what you've been shown on this thread, then throw in some unexpected data that'll match a success, but'll partially match a failure.

    You stated you've been bitten before, so you already know the answer to your own question.

Re^9: Adding hashes to already existing array
by stevieb (Canon) on May 06, 2016 at 23:19 UTC
    I'd like to see the code you end up with. There's been a lot of scratch, so once you're done and have things working, reply to this thread with your code. We're not a review service (typically), but in this case, I'm curious.

      The code I have is part of a larger system with lots of arrays and lots of data, and I'm afraid I have no way of getting it off and showing it. The code that I was using was the same as my first reply to you only with the variable names changed to protect the innocent. The results were also the same as in my reply with the data values also changed.

      I was interested in preserving the contents of the array, so I was trying not to destroy the data in it. That is why I was trying such unholy constructs. Looking at the answers that I received, I think that I will go with the ideas suggested by haukex and poj where I change the string value in the array into some hashes. It will require a little refactoring of places that access @excerpts (not its real name). To get the string contents, it will have to access $excerpts[$i]{content} instead of $excerpts[$i]. But it will now be possible to access $excerpts[$i]{fpart} and $excerpts[$i]{bpart} as well.