in reply to Re^3: Using variables in array names
in thread Using variables in array names

The biggest problem with symbolic references is polluting the package namespace.
I addressed that in my reply, and IMNSHO, that isn't the biggest problem. The vast majority of the problems I've seen when people use symbolic references (and when you give Perl classes you see a lot) stem from typos - not from "polluting" the package namespace.

Replies are listed 'Best First'.
Re^5: Using variables in array names
by herveus (Prior) on Aug 05, 2005 at 13:57 UTC
    Howdy!

    OK. But that doesn't make the solution invalid. It more likely suggests that the people getting into trouble from using symbolic references are both inexperienced and ignorant.

    The basic fact remains that hashes are the Right Tool for managing a collection of items identified by an arbitrary string. Your initial response conveyed the impression that you would deprecate using hashes with variable keys entirely, which, IMO, is absurd.

    yours,
    Michael
      But that doesn't make the solution invalid.
      No, and I never claimed it was invalid. I just objected to the phrasing that "you will be fine" - as it suggests you're suddenly immune from the perils of symbolic references. That's what I objected to.
        Well, if you don't use symbolic references then you're immune from the perils of symbolic references... your point, I think, was that using a complex structure, e.g. a HoA is not much advantageous over symrefs. Indeed the risk in connection with typos is exactly the same, but with what isn't it? And the problem with symrefs is that you're still manipulating package variable, whereas a hash can be a lexical one which often is better suited for whatever use one has in mind...
        Howdy!

        Your words conveyed a different impression.

        ...and I disagree with your statement...

        If you use a real hash (lexical, please) instead of symbolic references, you *are* immune to the perils of *symbolic references*. The problem of mistyping individual hash keys is a separate problem that afflicts both approaches. The big peril of symbolic references is that you have to take additional care to avoid stomping on the package variable names you create ad hoc.

        Your objection conflates these to facets.

        yours,
        Michael
Re^5: Using variables in array names
by shemp (Deacon) on Aug 05, 2005 at 17:50 UTC
    In regard to typos in hash keys, i have used various tied hashes that require registering any key before it is used. The definition of 'used' varies from implementation to implementation. In some cases i'd let it ask for existence of a non-registered key, but in other implementations, any action on a non-registered key is fatal. Etc, Etc, Etc.

    My use of this approach is pretty rare, and is not perfect because its run-time checks, but in certain critical apps (such as bulk changes to my data warehouse) this approach can be advantageous.

    I guess it comes down to a trade off of ease of use vs. level of checking.


    I use the most powerful debugger available: print!