bluebutton has asked for the wisdom of the Perl Monks concerning the following question:
$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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How can one determine context within FETCH?
by kyle (Abbot) on Oct 01, 2007 at 12:02 UTC | |
|
Re: How can one determine context within FETCH?
by jasonk (Parson) on Oct 01, 2007 at 12:53 UTC | |
|
Re: How can one determine context within FETCH?
by jeanluca (Deacon) on Oct 01, 2007 at 12:13 UTC | |
|
Re: How can one determine context within FETCH?
by Sidhekin (Priest) on Oct 01, 2007 at 13:15 UTC | |
|
Re: How can one determine context within FETCH?
by Anno (Deacon) on Oct 01, 2007 at 12:20 UTC | |
|
Re: How can one determine context within FETCH?
by clinton (Priest) on Oct 01, 2007 at 13:13 UTC |