Hello,. So here is my recursive
algorithm for you to compare and see.
-Dhiraj

#starts here
$total=0;
open(WH,"> output.txt");
binmode WH,":raw";
explore(".");
print "over..!\n";
print "total files=$total";
close WH;

sub explore
{
  my($dirname)=@_;
  my($x);
  unless($dirname eq "." || $dirname eq "..")
  { chdir $dirname; }
  local (*DIRH);   
  $status=opendir DIRH,".";
  if($status==0)
  {
    print "directory $dirname opening error\n";
    return;
  }

  print WH "Exploring directory $dirname...\n";
  print  "Exploring Directory $dirname\n";
  for $x (readdir DIRH)
  {
    if($x eq "." or $x eq "..")
    {  next; }

    if(-f $x)
    {
      print "$x\n";
      print WH "$x\n";
      $total++;
    }
    elsif(-d $x)
    {
      explore($x);
    }
  }
  closedir DIRH;
  chdir "...";
  return;
}
#ends here

On Mon, 28 Jan 2002 [EMAIL PROTECTED] wrote :
> > "Timothy Johnson" <> said:
> >  
> > Out of curiosity, is there a big performance increase 
> using a recursive
> > algorithm like the one described versus an algorithm 
> like below?  (This is
> > part of something I was working on a while ago, and I 
> wasn't using strict or
> > -w at the time, I'm still trying to train myself on 
> that one :P)
> 
> Recursive algorithms are generally easier to write and 
> easier to understand 
> when they are used for operating on recursive data 
> structures (e.g. trees). 
> 
> Writing non-recursive algorithms for operations on 
> recursive data
> structures means keeping track of one or more push down 
> stacks which
> can be error prone..  It is a good idea to understand 
> the relationship
> between stacks and recursion, since a stack is how 
> recursion is generally
> implemented.  But once you have gone thru the stack 
> exercise, let the
> compiler and the run time system do the bookkeeping for 
> you.
> 
> -- 
> Smoot Carl-Mitchell
> Consultant
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to