Perl-Sensitive Sunglasses | |
PerlMonks |
How can one determine context within FETCH?by bluebutton (Initiate) |
on Oct 01, 2007 at 09:13 UTC ( [id://641857]=perlquestion: print w/replies, xml ) | Need Help?? |
bluebutton has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to map a hash over a filesystem so that the following
is possible:
In other words, $mysystem->root returns a tied hash whose keys are the names of the files and directories in the root directory. However, I want the values to depend on the context. In scalar context:
the value should be a reference to another tied hash of the same class. In array context:
the value should a tied array representing the entire file as an array of lines (if the key is a file name) or a list of the contents of the directory (if the key is the name of a directory).. The problem is that using wantarray or looking at the caller() stack, I cannot seem to determine the context within FETCH; it's always scalar. My question is: Within the FETCH method of a tied hash, is there any other way to distinguish between:
and
Thanks in advance for any help you can give!
Back to
Seekers of Perl Wisdom
|
|