http://qs321.pair.com?node_id=195812

I have been reading my latest version of the Camel Book, and I wonder to myself... what good are tied variables?

Hear me out before anyone gets upset. First... one of people's complaints about perl is that it's far too hard to understand and read. While I don't agree, I think tied hashes add an unnecessary layer of complexity that doesn't make much sense when you already have objects.

Imagine a novice looking at the following two code snippets:

<newbiecommenting>

# tie tie $var, "classXYZ"; $var = 5; print $var; # yields 25... ??? # objects my $var = new Squareable(5); $var->square(); print $var; # oh... yields 25... neato!
</newbiecommenting>

Granted, this is a bit of a juvenile example, but do you see what I'm getting at? How is a novice supposed to be able to discern this type of behavior? In the second example, it's easy to tell what happened. Objects are more self-documenting even without POD.

I know modules like the Ordered Hash Tie module are helpful, but even that could have just been an object.

Perhaps I'm missing something, but I just don't understand Tied variables. Even tied filehandles are probably better just as an object or an extension of FileHandle. You formally declare your behavior instead of hiding it behind the way that perl NORMALLY behaves.

If someone could enlighten me as to some really good uses of tied hashes that make more sense than using a similarly coded object, please do. Perhaps I'm just looking at it wrong.

--
perl: code of the samurai