in reply to Depth First Search

What does your tree look like? (Show your code!)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Depth First Search
by gbar (Initiate) on Aug 10, 2016 at 08:04 UTC
    Hi lets say this I have this hash:
    my %document = ( '1' => { '1.1' => 'xxx', '1.2' => { '1.2.1' => 'xxx', '1.2.2' => 'xxx' } }, '2' => { '2.1' => { '2.1.1' => 'xxx' } } );
    and I would like to go over all of the children and then the fathers I will do it like this in perl 6 , I would like to find a why using perl5 to do the same .
    sub process (%chapters) { await do for %chapters.kv -> $number, $content { start { note "Chapter $number started"; &?ROUTINE.outer.($content) if $content ~~ Hash; sleep 1; # here the chapter itself is processed note "Chapter $number finished"; } } } process(%document);
    Thanks , for the help !

      Or more like this?

      #! perl -slw use strict; use threads; sub traverse { my $href = shift; $_->join for map async{ print "Chapter $_ started"; my $v = $href->{ $_ }; ref( $v ) eq 'HASH' and traverse( $v ); sleep 1; print "Chapter $_ finished"; }, keys %$href; } my %document = ( '1' => { '1.1' => 'xxx', '1.2' => { '1.2.1' => 'xxx', '1.2.2' => ' +xxx' } }, '2' => { '2.1' => { '2.1.1' => 'xxx' } } ); traverse( \%document ); __END__ C:\test>1169475 Chapter 1 started Chapter 2 started Chapter 1.1 started Chapter 1.2 started Chapter 2.1 started Chapter 1.2.2 started Chapter 1.2.1 started Chapter 2.1.1 started Chapter 1.1 finished Chapter 1.2.2 finished Chapter 1.2.1 finished Chapter 2.1.1 finished Chapter 1.2 finished Chapter 2.1 finished Chapter 1 finished Chapter 2 finished

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
        can I tell how much threads to open (max value of threads ? )

      Could you post the output from the P6 code? Does it look like this?:

      Chapter 1 started Chapter 1.1 started Chapter 1.1 finished Chapter 1.2 started Chapter 1.2.2 started Chapter 1.2.2 finished Chapter 1.2.1 started Chapter 1.2.1 finished Chapter 1.2 finished Chapter 1 finished Chapter 2 started Chapter 2.1 started Chapter 2.1.1 started Chapter 2.1.1 finished Chapter 2.1 finished Chapter 2 finished

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I am trying to do the following : I would like to send Getinfo as a tread until we passing the return until child is 0;
        sub GenerateVerilogFiles{ my ($self,$blockname)=@_; my $fileName = $BlockNameClass->{FileName}; $BlockNameClass->GetInfo($blockname); my $childFlag = ($fileName eq lala) ; return if($childFlag) ; foreach(my $x keys %{$BlockNameClass->{xxx}}) { GenerateVerilogFiles ($x); } }