in reply to File Indexing program

Have you used strict and warnings?

At a first look I see two potentially fatal problems here:

The use of local @current instead of my @current could work fine, but should be avoided and I'm not sure what can it do in a (deeply) recursive function.

The same applies to $temp and @mainarray, but this is not fatal as the first is not reused after recursion and the latter is intended to be a global. But it is anyway bad practice.

Bottom line: strict&warnings are your friends, (almost) always.

$i is not declared lexical (my) but is a global, so every recursion corrupts the value of $i of the previous and pending executions

Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Replies are listed 'Best First'.
Re^2: File Indexing program
by chetanspecial (Initiate) on Jun 24, 2008 at 19:30 UTC
    Thank you very much psini and that was fast. the only problem in the program was $i which was not localised.
    i must change $i to my $i.
    but i also observed that this was a lot slower than compared to a c++ program and took a lot of time.but anyway it worked perfectly. thanks again

      No, allow me to repeat: $i as global was the main problem in your program, it prevented the program to work.

      But it is not the only problem: all the other things I mentioned are time bombs waiting for the first time you change something in the code to explode.

      Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."