Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: [Perl 6] Any provision for a "dereferencing object"?

by rootcho (Pilgrim)
on Jun 01, 2007 at 04:54 UTC ( #618641=note: print w/replies, xml ) Need Help??


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";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://618641]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2021-05-10 18:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (106 votes). Check out past polls.

    Notices?