Tied Variables: One more reason to love Perl
As many of you know, tied variables lend extra magic to an otherwise normal Perl variable.
One of my favorites comes from
File::chdir. This provides your Perl script with
@CWD. When a folder is assigned to
$CWD or pushed onto
@CWD the working directory is changed, in a platform independent way. The coolest thing about this is if you first
local $CWD, then this change in the working directory is done locally to the block, and is undone as the scope ends.
Underneath the hood there is more tie magic!
Tie::File which provides random line access to a file as a Perl array. Using this module in mine allows the module to pick the row just like my users will, as an array index.
Version 0.03 adds a
new constructor. So that the users don’t even need to be aware of the
tie usage, which looks a little strange at first.
As far as I am aware, other languages don’t have anything like
tie. Just one more reason to love Perl! Which other Tie classes do you find especially interesting?