in reply to Re^2: Check if key exist in hash but not exact match
in thread Check if key exist in hash but not exact match
I tinkered some more:
There was a bug which I've fixed. I've no idea why, but I'd coded for only one NO_CASE. Obviously, you can have ABC, Abc, abc, AbC, and so on.
I decided that I was doing too much work with @matches. I changed that to %matches and, instead of removing elements from the array by recreating it using grep, I'm simply using delete to remove key/value pairs. This resulted in much cleaner code and, I imagine, would be a lot more efficient.
There was also an interesting point regarding the contents of the "Value" column produced by printf. Having introduced undef values in my test data for basic edge-case checks, this meant that there was either a price (number) or '<undefined>' (string). A %s worked fine for both when the price was 1.25; however, a price of 3.00 was converted to just 3.
My introduction of undef may have been completely artificial and would never occur in the OP's data: in this case, a %.2f would probably suffice throughout. I've left the undef values as it was an interesting exercise dealing with this. I can see potential improvements here but won't go into that further unless it is something the OP really wants.
As before, I'll put the new code and another sample run in a spoiler.
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Check if key exist in hash but not exact match
by ibm1620 (Hermit) on Apr 04, 2023 at 21:36 UTC | |
by LanX (Saint) on Apr 04, 2023 at 21:51 UTC | |
by eyepopslikeamosquito (Archbishop) on Apr 04, 2023 at 22:23 UTC | |
by kcott (Archbishop) on Apr 04, 2023 at 22:41 UTC | |
by ibm1620 (Hermit) on Apr 05, 2023 at 12:11 UTC |