$root = $mysystem->root; $proc = $root->{'proc'}; print "Uptime is ", $proc->{'uptime'}[0], "\n";
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.$passwd = $root->{'etc'}->{'passwd'}; $spool = $root->{'var'}->{'spool'};
In array context:
$line = $root->{'etc'}->{'passwd'}[0] # First line of passwd file @names = $root->{'var'}->{'spool'}; # List of files/dirs
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:
$proc->{'/var'}
and
$proc->{'/var'}[0]
Thanks in advance for any help you can give!
In reply to How can one determine context within FETCH? by bluebutton
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |