in reply to [Perl 6] Any provision for a "dereferencing object"?

hmm..
In perl6 could we have something like this then :)
my %hash = ( foo => { foo1 => {foo2 => 5 } }, bar => { baz => [ 1,2,3 ], foo2 => 33 }, ... )
and then access this like :
$hash<*><foo2> $hash<//><foo2>
In this case '*' and '//' mean the same thing (just for illustration. regex-like and xpath-like syntax).
This should return all 'foo2' element no matter how deep. Or :
$hash<bar><//><foo2>
Return only the second 'foo2'..and so on.. you get the idea.
Or this better be done with external module ?
This will make very easy implementing XPath and similar tools.

Replies are listed 'Best First'.
Re^2: [Perl 6] Any provision for a "dereferencing object"?
by TimToady (Parson) on Jun 01, 2007 at 06:13 UTC
    Well, it would be wicked to use <*> to hold magic cookies, since that construct is supposed to only contain literal strings. However, Perl 6 already specs a multidimensional syntax in Synopsis 9 to do what you want:
    $hash{ **; 'foo2'} $hash{ 'bar'; **; 'foo2' }
    Whether this is actually implementable is another question...

      I don't see why it wouldn't be. At worst, you would need to do a breadth-first search through the whole datastructure (which, in the general case, is likely to be a graph rather than a tree). Of course, this may be terribly slow, but surely it's implementable.

      --
      print "Just Another Perl Adept\n";