|No such thing as a small change|
Re^4: simple table join scriptby sauoq (Abbot)
|on Jun 01, 2012 at 14:44 UTC||Need Help??|
Yes - it SORTS them.
Where did he say changing the order in any manner was what he wanted? The issue is that your code essentially requires reordering in some manner because of your poor choice to use hashes which will destroy the original order. You left yourself with the choice to either sort or go with whatever reordering perl gives you.
That's not a nit. Not being able to retain the original order is a fundamental issue. Perhaps he doesn't need to. He didn't say. But if he does need to, your code is worthless.
The efficiency issue may or may not be of practical importance. But its only an issue at all because of the same aforementioned poor design decision. The straight forward approach I showed isn't better because it's more efficient... it's more efficient because it's better.
Correction - it splits on WHITESPACE, that includes tab.
That's right. And thanks for picking a nit with my point... I like precision. It's still a potential problem because he didn't specify whether his fields could have other whitespace... and if they did, your code would break. That's a little less data tolerant, arguably, than some warnings on blank lines.† I called it "minor" because it is so easily corrected, unlike your code's other issues.
Note that adding sorting to the straight forward approach is easily done with a single sort if desired.
Note also that skipping blank lines is easily added to the straight forward approach with an appropriately placed next unless /\S/; or similar.
† Warnings on blank lines may actually be desirable. It's often a good think to throw a warning on data anomalies.
"My two cents aren't worth a dime.";